当前位置:   article > 正文

element-ui中table表格标签编辑功能的实现_element ui table 可编辑

element ui table 可编辑

项目场景:

表格实现编辑功能。在实际开发过程中,我们表格的表头往往很多,有的还会发生变化,所以本文参考一位博主的代码结合自己的项目进行了改编。
参考原文链接:vue element-ui实现table表格可编辑修改


代码展示

<template>
    <div class="st-table">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column v-for="(item, index) in columns" :key="index" fixed :prop="item.prop" :label="item.label"  width="180">
        <template slot-scope="scope">
          <input type="text" v-model="scope.row[item.prop]" v-show="scope.row.iseditor" />
          <span v-show="!scope.row.iseditor">{{scope.row.date}}</span>
        </template>
      </el-table-column>
      
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="warning" @click="edit(scope.row, scope)">编辑</el-button>
          <el-button type="danger" @click="save(scope.row)">保存</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
        columns:[
            {prop:'date',label:'时间',width:'150'},
            {prop:'name',label:'姓名',width:'150'},
            {prop:'address',label:'地址',width:'150'},
        ],
        tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          iseditor: false
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
          iseditor: false
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
          iseditor: false
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
          iseditor: false
        }
      ]
    }
  },
  methods:{
  	edit(row, index) {
      row.iseditor = true;
    },
    save(row, index) {
      row.iseditor = false;
    }
  }
}
</script>

<style scoped>

.st-table {
  padding: 10px;
}
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75

结果图展示:

在这里插入图片描述
在这里插入图片描述


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/201156
推荐阅读
相关标签
  

闽ICP备14008679号