element ui Table 根据后台返回的表头列表 动态显示列 和 双击单元格 修改单元格内的内容

附上代码

<template>
  <div class="hello">
    <el-table :data="tableData" @cell-dblclick="handle" style="width: 100%">
      <template v-for="(item,index) in tableTitle" >
        <el-table-column :prop="item.prop" :label="item.lable" :key="index" width="300" align="center">
          <template slot-scope="scope">
              <div  class="tableEditInput" v-if="scope.row.isEdit && scope.row.EditName==scope.column.property">
                <el-input v-model="qdata[item.prop]" :id="scope.row.IntExcelLine+scope.column.id"  @blur="editEmployee(scope.row,scope.column)"></el-input>
              </div>
              <div v-if="!scope.row.isEdit || scope.row.EditName!=scope.column.property">{{ scope.row[item.prop] }}</div>
            </template>
        </el-table-column>
      </template>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //临时数据
      qdata:"",
      //表格数据
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎1",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          date: "2016-05-04",
          name: "王小虎2",
          address: "上海市普陀区金沙江路 1517 弄"
        },
        {
          date: "2016-05-01",
          name: "王小虎3",
          address: "上海市普陀区金沙江路 1519 弄"
        },
        {
          date: "2016-05-03",
          name: "王小虎4",
          address: "上海市普陀区金沙江路 1516 弄"
        }
      ],
      //表头列表
      tableTitle:[
        {lable:"日期",prop:"date"},
        {lable:"名称",prop:"name"},
        {lable:"地址",prop:"address"},
      ],
    };
  },
  mounted() {},
  methods: {
    //双击单元格修改  input
    handle(row, column, cell, event) {
      this.qdata = row;
      //使用 this.$set 往row里插入 控制input显示隐藏的参数
      this.$set(row, "isEdit", true);
      this.$set(row, "EditName", column.property);
      console.log("colum", row, column, cell, event);
      console.log(row.IntExcelLine + column.id);
    },
    //修改完成后隐藏input
    editEmployee(row){
      //使用this.$delete 删除参数
       this.$delete(row, "isEdit");
       this.$delete(row, "EditName");
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
>>> .el-input {
  width: 100%;
}
</style>
<style>
</style>
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值