el-date-picker默認(rèn)數(shù)據(jù)之后修改不渲染的問題

通常我們在寫新增修改時(shí),修改會用到回顯數(shù)據(jù)的問題,但是偶爾有出現(xiàn)change事件/input事件改變了form數(shù)據(jù),頁面并沒有渲染的問題,同時(shí)一鍵刪除按鈕也不能渲染,萬變不離其宗,給組件加個key就好啦。
如下:

<el-date-picker :key="itemKey" :default-time="['00:00:00', '23:59:59']"  
v-model="form.date"  @input="createTimeFn" type="datetimerange" 
 range-separator="至" start-placeholder="開始日期" end-placeholder="結(jié)束日期" 
style="min-width:600px">
 </el-date-picker>
import {cloneDeep} from 'lodash';
props: {
    config: {
      type: Object,
      default: {}
    }
  },
data() {
    return {
      itemKey:null,// 關(guān)鍵參數(shù)key
      // 表單參數(shù)
      form: {
        startTime: undefined,
        endTime: undefined,
        date: [],
      },
 }
},
created() {
    this.initData()
  },
 methods: {
      // 時(shí)間選擇
    createTimeFn (val) {
      this.itemKey = Math.random();//給key賦隨機(jī)值
      if (this.form.date) {
        this.form.startTime = val[0].getTime();
        this.form.endTime = val[1].getTime();
      } else {
        this.form.endTime = null;
        this.form.startTime = null;
      }
    },
// 初始化數(shù)據(jù)
initData() {
      this.itemKey = Math.random();// 初始化賦值 key
      if (this.config.editFrom) {
        let {startTime,endTime} = this.config.editData;
        this.form = cloneDeep(this.config.editData);
        this.form.date = [new Date(startTime),new Date(endTime)]
      } else {
        this.reset();
      }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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