Ant Design moment对象和字符串之间的相互转化教程
moment对象转字符串
values.saleStartTime=values.saleStartTime.format('YYYY-MM-DD');
字符串转moment对象
this.model.saleStartTime=moment(record.saleStartTime);
补充知识:vueantdesign的日期组件range-picker表单中进行moment赋值问题
官方文档这样写
参数 | 说明 | 类型 |
---|---|---|
showTime.defaultValue | 设置用户选择日期时默认的时分秒 | moment[] |
之前进行过普通票哪个的datepicker赋值
区别是range-picker是将两个日期存成了moment[]类型的数组
这个就比较操蛋了,后台不想拆成2个字段,只好把它转成字符串
formData.showDate=formData.showDate.join(',')
然而,再拿回来转成数组去赋值,不行……
具体原因找了好久才对比出来,原因不说了,看一下正确的流程
formData.showDate=[formData.showDate[0].toISOString(),formData.showDate[1].toISOString()];
formData.showDate=formData.showDate.join(',')
然后赋值就是正常赋值:
this.model.showDate?this.model.showDate=[moment(this.model.showDate[0],'YYYY-MM-DDHH:mm:ss'),moment(this.model.showDate[1],'YYYY-MM-DDHH:mm:ss')]:null this.form.setFieldsValue({showDate:this.model.showDate?this.model.showDate:null})
以上这篇AntDesignmoment对象和字符串之间的相互转化教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。