warning.js?2149:7 Warning: [antdv: DatePicker] `value` provides invalidate moment time. If you want to set empty value, use `null` instead.
以上是antd表单赋值日期组件遇到的报错
解决:
this.$nextTick(() => {
formData = this.infoForm.getFieldsValue();
for (let i in formData) {
infoValues[i] = infoData[i] || infoData[i] == 0 ? infoData[i] : undefined;
typeof infoValues[i] == "string" ?
(infoValues[i] = infoValues[i].replace(/(^\s*)|(\s*$)/g, "")) :
"";
};
this.infoForm.setFieldsValue({
...infoValues,
communicationMode: !infoData.communicationMode
? undefined
: infoData.communicationMode.split(","),
devPowerSupply: !infoData.devPowerSupply
? undefined
: infoData.devPowerSupply.split(","),
fixedType: !infoData.fixedType
? undefined
: infoData.fixedType.split(","),
devUsageTime: infoData.devUsageTime? moment(infoData.devUsageTime): null // 需转成moment格式,不然会报错
});
})
注意细节:1、…infoValues放最上面,其它项赋值放下面,以防后台返回的字段或者格式不符合前端的渲染!2、moment记得引入噢
等风来不如追风去,向着目标不断前进吧!