調用方法:Vue.set( target, key, value ) target:要更改的數據源(可以是對象或者數組) key:要更改的具體數據 value :重新賦的值
具體用法
js代碼:
//設置初始狀態和值
let j = { id: 0, "progressTime": "", "progressContent": "", "isSet": true, "_temporary": true };
_this.tableInFormData = []
//將對象加入到數組
this.tableInFormData.push(j);
//項目將isSet變為true 從而v-if來判斷輸入框可以使用
_this.$set(_this.tableInFormData[index],"isSet",true)
下面放html代碼:
<el-table-column label="時間" width="300" :show-overflow-tooltip="true"> <template slot-scope="scope" > <span v-if="scope.row.isSet"> <el-date-picker v-model="form2.progressTime" type="datetime" :picker-options="pickerBeginDateBefore" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="選擇日期"> <!--:disabled="true">--> </el-date-picker> </span> <span v-else>{{changeTimeToDate(scope.row.ProgressTime) }}</span> </template> </el-table-column> <el-table-column prop="ProgressContent" label="處置進展" :show-overflow-tooltip="true"> <template slot-scope="scope"> <span v-if="scope.row.isSet"> <el-input size="small" v-model="form2.progressContent" placeholder="請輸入內容" ></el-input> </span> <span v-else>{{(scope.row.ProgressContent) }}</span> </template> </el-table-column>