双击编辑el-table的单元格数据

(1) el-table刷新要求绑定el-table的key要发生变化才会刷新

(2) 单元格双击事件 cell-dblclick

(3) 往row里面添加一个属性来唯一标识某一行的数据,双击时使这特殊属性为true,输入框失去焦点时则设置特殊属性为false,并且输入框的显示与隐藏通过v-if与特殊属性绑定。

(4) 回车事件 @keyup.enter.native

javascript 复制代码
<el-table border class="mt20" :data="data" style="width: 100%" row-key="id" :key="key" @cell-dblclick="dblclick">
      <el-table-column type="index" label="序号" width="50">
        <template slot-scope="scope">
          <span>{{ (search.page -1) * search.size + scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="ID" width="width">
      </el-table-column>
      <el-table-column prop="name" label="名称" width="width">
      </el-table-column>
      <el-table-column prop="lwkx" label="论文扩写" width="width">
          <template scope="scope">
            <div v-if="scope.row[scope.column.property+'Show']" class="input-box">
              <el-input size="small" @keyup.enter.native="handleInputlwkx(scope.row,scope.column)" v-model="scope.row.lwkx"></el-input>
            </div>
            <span v-else>{{scope.row.lwkx}}</span>
          </template>
        </el-table-column>
    </el-table>

<script>
export default {
data() {
    return {
      key: "",
      dialogVisible: false,
      search: {
        page: 1,
        size: 20,
      },
      data: [],
      total: 0,
    };
  },
methods: {
    dblclick: function (row, column) {
      console.log(column.property);
      row[column.property + "Show"] = false;
      row[column.property + "Show"] = true;
      this.updateTable();
    },
    // 修改论文扩写
    handleInputlwkx(row, column) {
      row[column.property + "Show"] = true;
        //业务代码
      funcGroupUpdate(row).then((res) => {
        this.dialogVisible = false;
        this.$message.success(res.message);
      });
    },
 //更新表格
    updateTable() {
      this.key = Math.random();
    },
}
}
</script>

双击编辑el-table的单元格_el-table 单元格-CSDN博客

相关推荐
paopaokaka_luck1 天前
基于SpringBoot+Vue的社区诊所管理系统(AI问答、webSocket实时聊天、Echarts图形化分析)
vue.js·人工智能·spring boot·后端·websocket
余道各努力,千里自同风1 天前
el-input 输入框宽度自适应宽度
javascript·vue.js·elementui
Mike_jia1 天前
DumbAssets:开源资产管理神器,家庭与企业的高效管家
前端
Southern Wind1 天前
Vue 3 多实例 + 缓存复用:理念及实践
前端·javascript·vue.js·缓存·html
一大树1 天前
Vue3优化指南:少写代码,多提性能
vue.js
HuangYongbiao1 天前
Rspack 原理:webpack,我为什么不要你
前端
yinuo1 天前
前端项目开发阶段崩溃?试试这招“Node 内存扩容术”,立马复活!
前端
前端鳄鱼崽1 天前
【react-native-inspector】全网唯一开源 react-native 点击组件跳转到编辑器
前端·react native·react.js
用户98402276679181 天前
【React.js】渐变环形进度条
前端·react.js·svg
90后的晨仔1 天前
Webpack完全指南:从零到一彻底掌握前端构建工具
前端·vue.js