加入本行的數據為scope.row,其數據格式為
{
"propertyId": 4,
"propertyName": "標題",
"propertyType": 0
}
如果這里v-show=“scope.row.edit”,因為scope.row本來沒有edit這個字段,當在vue的methods中改變edit值時,不能立刻反應在view中。
所以只能綁定scope.row已存在的字段,但是又出現一個問題,改變綁定的字段時數據的變化會反應在表格數據上。
解決辦法:綁定scope.row.propertyId,不改變其值,改變其類型,根據其類型設置按鈕是否顯示
<el-table-column label="操作"> <template scope="scope"> <el-button size="small" type="primary" icon="edit" @click="handleEdit(scope.$index, scope.row)" v-show="typeof(scope.row.propertyId)=='number'"></el-button> <el-button size="small" type="danger" icon="delete2" @click="handleDelete(scope.$index, props.row.properties)" v-show="typeof(scope.row.propertyId)=='number'"></el-button> <el-button size="small" type="warning" icon="check" @click="handleEditOk(scope.$index, scope.row)" v-show="typeof(scope.row.propertyId)!=='number'"></el-button> </template> </el-table-column>
methods中
handleEdit(index, rowData) {
rowData.propertyId = rowData.propertyId.toString();
}
后來摸索,找到了最終解決方案:動態給所有數組記錄 添加edit屬性,
JSON.parse(JSON.stringify(this.archives.paperRecord ? this.archives.paperRecord : []))
<el-table :data="recordTable"> </el-table
let data = JSON.parse(JSON.stringify(this.archives.paperRecord ? this.archives.paperRecord : []))
data.forEach(element => {
element['edit'] = false
});
this.recordTable = data