ant design vue + ts 時遇到的坑之from 表單

在做vue+ant design? vue + ts 時遇到的坑:

1. from表單回顯時間日期遇到的問題

我們需要借助 moment 來做一下處理? ant design vue 官方給出?

import momentfrom 'moment';

import 'moment/locale/zh-cn'

moment.locale('zh-cn');

在我們的頁面:newstime: moment(res.data.rows[0].newstime, 'YYYY-MM-DD')

這樣回顯就不會報錯了

2.You cannot set a form field before rendering a field associated with the value.

剛開始是這樣寫的 尋思也沒啥問題,頁面展示也沒有問題,但是報錯了this.form.setFieldsValue(Object.assign({},res.data.rows[0],{"newstime": moment(res.data.rows[0].newstime, 'YYYY-MM-DD')}));

解決方案 :

將返回的是分別寫出來

this.form.setFieldsValue({

newstitle : res.data.rows[0].newstitle,

? ? newstype : res.data.rows[0].newstype,

? ? newsimg:res.data.rows[0].newsimg,

? ? newscontent:res.data.rows[0].newscontent,

? ? newstime: moment(res.data.rows[0].newstime, 'YYYY-MM-DD')

})

這樣報錯就解決了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容