我在表单中使用 antd
的 DatePicker
组件,想更改默认的 onChange
和 value
DatePicker
中的 Prop ,但它不起作用。
<Form.Item
label='Test Label'
name='startDate'
getValueFromEvent={(onChange) => moment(onChange).format('YYYY-MM-DD')}
getValueProps={(i) => moment(i)}
>
<DatePicker format='YYYY-MM-DD' style={{ width: '100%' }} />
</Form.Item>
当我在表单之外使用 DatePicker
时,它会起作用:
<DatePicker value={moment()} style={{ width: '100%' }} />
这是 getValueProps
属性的问题吗?
最佳答案
我修好了!
如果有人有同样的问题:
您必须将 getValueProps
更改为如下内容:
getValueProps={(i) => ({value: moment(i)})}
关于reactjs - Ant 设计 DatePicker 的形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71594682/