当前位置: 首页 > article >正文

Vue ElemetUI table实现双击修改编辑某个内容

1、使用@cell-dblclick事件,当双击时触发事件

<el-table @cell-dblclick="handleCellDblClick"

2、单元格设置

主要重点为判断双击时切换input框,然后绑定ref,设置失去焦点时触发点方法,与按enter键触发点方法

<el-table-column prop="name" label="姓名" width="180">
      <template slot-scope="scope">
        <span v-if="editableData !== scope.row">{{ scope.row.name }}</span>
        <el-input
          v-else
          :ref="'input-' + scope.$index"
          v-model="scope.row.name"
          @blur="handleInputBlur(scope.row)"
          @keyup.enter.native="handleInputEnter(scope.row)"
        ></el-input>
      </template>
    </el-table-column>

3、添加当前编辑的数据

editableData: null, // 当前编辑的数据项

4、为所有的方法赋予逻辑

// 双击时触发
handleCellDblClick(row, column, cell, event) {
  if (column.property === 'customerBoxNum') {
    this.editableData = row; // 设置当前编辑的数据项
    this.$nextTick(() => {
      const inputRef = 'input-' + this.boxList.indexOf(row);
      const inputElement = this.$refs[inputRef];
      if (inputElement) {
        inputElement.focus(); // 聚焦输入框
      } else {
        console.error('Input element not found:', inputRef);
      }
    });
  }
},
handleInputBlur(row) {
  // 输入框失去焦点时保存更改
  this.editableData = null; // 返回到静态显示状态
},
handleInputEnter(row) {
  // 按下回车键时保存更改
  this.editableData = null; // 返回到静态显示状态
},

5、打完收工


http://www.kler.cn/news/323684.html

相关文章:

  • Leecode刷题之路从今天开始
  • 面经 | ES6
  • 时间技能物品竞品抢拍拍卖发布h5公众号小程序开源版开发
  • VueUse-----基于 Vue 3 的实用工具库,常用功能介绍及使用案例
  • 代码随想录第二十天:动态规划、斐波那契数列、爬楼梯、最小体力爬楼梯
  • Java网络编程、正则表达式、单例设计模式与Lombok
  • 南平自闭症寄宿制学校:让孩子自信绽放
  • 什么是后端开发 ?
  • 安装 Nacos 启动报错 java.lang.IllegalArgumentException: db.num is null
  • JavaWeb图书借阅系统
  • 【3D分割】Segment Anything in 3D with Radiance Fields
  • 【MySQL】数据库基础认识
  • GIS--为研究区准备数据
  • 基于STM32的远程工业控制系统架构设计:MQTT通信、React界面与FreeRTOS优化的综合应用
  • 【React】原理
  • 微信小程序开发第八课
  • 16.第二阶段x86游戏实战2-发包函数和怎么去找改写过的发包函数
  • 进程与线程之间的关系与区别
  • C++20中头文件compare的使用
  • 数据仓库简介(一)
  • 鸿蒙OS开发之动画相关示例分享, 关于弹出倒计时动画的实战案例源码分享
  • netty之Future和Promise
  • leetcode946. 验证栈序列
  • ARM GNU工具链
  • 赵长鹏今日获释,下一步会做什么?币安透露2024年加密货币牛市的投资策略!
  • 【数据结构-栈】力扣71. 简化路径
  • react-native如何一个项目生成两个安装包
  • 什么是Kafka?
  • 利用 Llama-3.1-Nemotron-51B 推进精度-效率前沿的发展
  • PlayerPerfs-不同平台的存储位置