參考另一個大神寫的:https://blog.csdn.net/weixin_42769637/article/details/107815831
情景描述(vue中,其他環境不清楚)
問題出現情況一、
寫增加和修改功能,form一樣,為了省事兩個用了同一個form。在修改時,回顯后的日期選擇控件無法修改了。
測試后發現修改后的數據可以得到,也就是只是頁面顯示問題。
問題出現情況二、
就是在新增得時候給日期選擇框設置默認值位當前時間得時候,也無法點擊選擇和刪除這個初始值,我當時遇到得是這個情況
第二種應用場景得代碼:
<el-date-picker style="width: 135px !important" size="small" value-format="yyyy-MM-dd" v-model="rowData.startTime" type="date" placeholder="請選擇" > </el-date-picker> for (let index = 0; index < this.tableData.data.length; index++) { // this.tableData.data[index].startTime = this.getNowFormatDate(); // this.tableData.data[index].endTime = this.getNowFormatDate(); this.$set(this.tableData.data[index],'startTime',getNowFormatDate()) this.$set(this.tableData.data[index],'endTime',getNowFormatDate()) } /** * @description: 返回當前日期得字符串格式 * @auther: 張琴 */ export function getNowFormatDate() { let date = new Date(); let seperator1 = "-"; let year = date.getFullYear(); let month = date.getMonth() + 1; let strDate = date.getDate(); if (month >= 1 && month <= 9) { month = month; } if (strDate >= 0 && strDate <= 9) { strDate = strDate; } let currentdate = year + seperator1 + month + seperator1 + strDate; return currentdate; }