当前位置:   article > 正文

vue element-ui实现table表格可编辑修改_element ui table 可编辑

element ui table 可编辑

代码如下:点击编辑按钮可编辑当前行,点击保存可以保存当前行,可以结合业务需要,进一步修改

  1. <template>
  2. <div class="st-table">
  3. <el-table :data="tableData" border style="width: 100%">
  4. <el-table-column prop="date" label="日期" width="180">
  5. <template slot-scope="scope">
  6. <input type="text" v-model="scope.row.date" v-show="scope.row.iseditor" />
  7. <span v-show="!scope.row.iseditor">{{scope.row.date}}</span>
  8. </template>
  9. </el-table-column>
  10. <el-table-column prop="name" label="姓名" width="180">
  11. <template slot-scope="scope">
  12. <input type="text" v-model="scope.row.name" v-show="scope.row.iseditor" />
  13. <span v-show="!scope.row.iseditor">{{scope.row.name}}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column prop="address" label="地址">
  17. <template slot-scope="scope">
  18. <input type="text" v-model="scope.row.address" v-show="scope.row.iseditor" />
  19. <span v-show="!scope.row.iseditor">{{scope.row.address}}</span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="操作" width="180">
  23. <template slot-scope="scope">
  24. <el-button type="warning" @click="edit(scope.row, scope)">编辑</el-button>
  25. <el-button type="danger" @click="save(scope.row)">保存</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. tableData: [
  36. {
  37. date: "2016-05-02",
  38. name: "王小虎",
  39. address: "上海市普陀区金沙江路 1518 弄",
  40. iseditor: false
  41. },
  42. {
  43. date: "2016-05-04",
  44. name: "王小虎",
  45. address: "上海市普陀区金沙江路 1517 弄",
  46. iseditor: false
  47. },
  48. {
  49. date: "2016-05-01",
  50. name: "王小虎",
  51. address: "上海市普陀区金沙江路 1519 弄",
  52. iseditor: false
  53. },
  54. {
  55. date: "2016-05-03",
  56. name: "王小虎",
  57. address: "上海市普陀区金沙江路 1516 弄",
  58. iseditor: false
  59. }
  60. ]
  61. };
  62. },
  63. methods: {
  64. edit(row, index) {
  65. row.iseditor = true;
  66. },
  67. save(row, index) {
  68. row.iseditor = false;
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="less" scoped>
  74. .st-table {
  75. padding: 10px;
  76. }
  77. </style>

 

 

 

 转自:vue element-ui实现table表格可编辑修改_八佾舞于庭的博客-CSDN博客

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

闽ICP备14008679号