vue + element plus 实现可编辑table

<el-table :data="tableData">
    <el-table-column label="序号" type="index"></el-table-column> 
    <el-table-column label="位置"> 
<template #default="scope">
<el-input :model-value="scope.row.positionCode" @input="value => handleInputChange(value, scope.row.index)">
</template>
</el-table-column>
</el-table>

可通过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
  }
}

 

vue + element plus 实现可编辑table

上一篇:处理椭圆和矩形的面积相交问题


下一篇:PRA006/PRA010 开发板,Quartus Altera JTAG 配置,以及常见故障解决