问题
AntD时间组件Datepicker只支持格式为moment类型的数据,不支持string类型的数据。在Form表单中,为了传值,将moment类型转换为了string类型,导致页面崩掉,报错信息:date.clone is not a function
解决
因为之前将moment类型转为了string类型,所以去掉结尾的format("YYYY-MM-DD"),保留其余代码。
因为在Form组件中,无需onChange获取、改变时间,自动取中国时区时间。但是保存时为国际标准时间UTC'2021-01-02T10:00:00.000Z'这样子,相差8小时。用moment的add方法矫正时间。
import moment from 'moment';
if(typeof(item.date) === 'object') {
item.date = moment(new Date(item.date)).add(8, 'hour')
}
参考
antd Datepicker组件——date.clone is not a function
挺好的,但是没用上
[BUG]moment.js:93 Uncaught TypeError: date.clone is not a function #368
知道了AntD时间组件只支持moment类型
antd中DatePicker选择此刻获取的时间不正确(多了8小时)解决办法
需要moment类型所以没有用上
版权声明:本文为qq_40138556原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。