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

Vue ElemetUI table的行实现按住上下键高亮上下移动效果

1、添加初始化的方法

// 添加键盘事件监听器:
mounted() {window.addEventListener('keydown', this.handleKeydown);},
// 这段代码的作用是在 Vue 组件销毁之前移除一个键盘事件监听器
// 这样做可以确保当组件不再使用时,不会留下任何未清理的事件监听器,从而避免内存泄漏等问题。
beforeDestroy() {window.removeEventListener('keydown', this.handleKeydown);}

2、在el-table中添加 @current-change方法

// 如下
<el-table  @current-change="handleCurrentChange">

3、添加对应键盘操作方法

handleCurrentChange(val) {this.currentRow = val;
},
handleKeydown(event) {console.log(event.keyCode)if (event.keyCode === 38) { // 按下上键this.highlightPrevRow();} else if (event.keyCode === 40) { // 按下下键this.highlightNextRow();}
},
highlightPrevRow() {const index = this.boxList.indexOf(this.currentRow) - 1;if (index >= 0) {this.$refs.tableRef.setCurrentRow(this.boxList[index]);}
},
highlightNextRow() {const index = this.boxList.indexOf(this.currentRow) + 1;if (index < this.boxList.length) {this.$refs.tableRef.setCurrentRow(this.boxList[index]);}
},

4、还可以为高亮设置自定义颜色

.el-table--striped .el-table__body tr.el-table__row--striped.current-row td,
.el-table__body tr.current-row>td {color: #fff;background-color: #adeda6 !important;
}


http://www.mrgr.cn/news/34856.html

相关文章:

  • 剑侠情缘c++源码全套(增加缺失的头文件和相关的库,其它网上流传的都是不全的)剑网三源码
  • springboot中药材进存销管理系统
  • 一例H-worm变种的分析
  • 拼团活动开发秘籍:PHP+Redis实现暂存成团信息,提升效率!
  • JDBC 与 Mybatis 对比
  • 软件架构设计原则
  • Java:列表操作
  • C++:类中的特殊内容
  • 基于BeagleBone Black的网页LED控制功能(Flask+gpiod)
  • Vue学习记录之八(局部组件,全局组件,递归组件,动态组件)
  • C++学习笔记----8、掌握类与对象(一)---- 对象中的动态内存分配(1)
  • Redis 的 Java 客户端有哪些?官方推荐哪个?
  • 末端无人配送产业链
  • MyBatis参数处理
  • JAVA无缝沟通全球国际版多语言语聊系统小程序源码
  • SOMEIP_ETS_127: SD_Multicast_FindService
  • Electron 更换窗口图标、exe执行文件图标
  • 工博会蓝卓逛展攻略
  • Pandas DataFrame 对象的基本操作
  • Reis数据库及key的操作命令汇总