使用Ant Design Pro的react组件的时候,用form表单做详情显示的时候 报一个警告Warning:
index.js:1 Warning: defaultValue
is invalid for getFieldDecorator
will set value
, please use option.initialValue
instead.
使用的DatePicker组件
state = {
birthday: '2019-5-31'
};
const {
form: { getFieldDecorator, getFieldValue },
} = this.props;
<FormItem
{...formItemLayout}
label={
<span>
<FormattedMessage id="form.date-birth"/>
<em className={styles.optional}>
<FormattedMessage id="form.must-fill"/>
</em>
</span>
}
>
{getFieldDecorator('birthday',{
})(
<DatePicker
placeholder="请选择"
defaultValue={moment(this.state.birthday, 'YYYY-MM-DD')}
format="YYYY-MM-DD"
style={{ width: '100%' }}
/>,
)}
</FormItem>
使用initialValue也出错
{getFieldDecorator('birthday',{
initialValue: `2019-11-11`,
})(
<DatePicker
placeholder="请选择"
// defaultValue={moment(this.state.birthday, 'YYYY-MM-DD')}
format="YYYY-MM-DD"
style={{ width: '100%' }}
/>,
)}
这出错没看懂,各位大佬帮忙看下
initialValue
的值使用moment()格式化,DatePicker接收的是moment对象