当前位置:   article > 正文

Element-UI table 单元格数据可编辑_elementui 可编辑table

elementui 可编辑table

Element-UI table 单元格数据可编辑

一开始的状态点击编辑

点击保存

// template代码
<el-table v-loading="loading" :data="tabels" @selection-change="handleSelectionChange">
  <el-table-column type="selection" width="55" align="center" />
  <el-table-column label="表名" prop="name" width="120" align="center"/>
  <el-table-column label="表解释" width="200" align="center">
    <template slot-scope="scope">
      <el-input 
      placeholder="请输入内容" 
      v-model="scope.row.remark" 
      :disabled="scope.row.update == 0?true:false" 
      style="width:75%"
      ></el-input>
      <i 
      class="el-icon-edit-outline" 
      style="margin-left:10px" 
      v-if="scope.row.update == 0" 
      @click="scope.row.update = 1"
      ></i>
      <i 
      class="el-icon-check" 
      style="margin-left:10px" 
      v-else 
      @click="updateRemark(scope.row)"
      ></i>
    </template>
  </el-table-column>
</el-table-column>

// script代码
<script>
import { getTableList,updateRemark } from "@/api/table";

export default {
  name: "Role",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      tabels: [],
      // 遮罩层
      loading: true,
    };
  },
  created() {
    this.getList();
  },
  methods: {
  // 更新表中数据
    updateRemark(rows){
      console.log(rows)
      updateRemark({id:rows.id,remark:rows.remark}).then(
        res=>{
          console.log(res)
          // 修改update状态为不可编辑
          rows.update = 0
        }
      );
    },
    handleClick(rows){
      console.log(rows) 
    },
    // 获取表格数据
    getList(){
      getTableList().then(
        res=>{
          // 为每条数据加上update来控制是否编辑
          // update为0是,不可编辑,为1时,可编辑
          res.rows.forEach(item =>{
            item.update = 0
          })
          this.tabels = res.rows
          this.loading = false
        }
      );
    },
    // 选择器
    handleSelectionChange(e){
      console.log(e)
    }
  }
}
  • 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
  • 76
  • 77
  • 78
  • 79
  • 80
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/201165
推荐阅读
相关标签