vue + element plus 实现可编辑table
"tableData">
"位置">
default="scope">
"scope.row.positionCode" @input="value => handleInputChange(value, scope.row.index)">
可通过table插槽实现,需要使用model-value进行绑定,v-model绑定会出现不能单个绑定、一列值均发生变化的情况,通过触发input事件为table单元格赋值
js
data() { return{ tableData: [] } } methods: {
// table动态生成多少条数据
countChange (num) {
this.currentData = []
var index = 0
var obj = {}
for(var i = 0; i < num; i++){
index++
obj = {
index: index,
positionCode: null
}
this.currentData.push(obj)
}
}
handleInputChange(val, index){
this.currentData[index - 1].positionCode = val
}
}