vue3使用Element Plus的el-table,高亮当前点击的单元格

⭐主要使用el-tablecell-style属性cell-click事件

1、给el-table添加cell-style属性和cell-click事件

html 复制代码
<el-table
	:data="state.dataList"
	style="width: 100%"
	border
	v-loading="state.loading"
	:cell-style="cellStyle"
	@cell-click="cellClick"
>
<!-- 这里写el-table-colum 章小鱼省略-->
</el-table>

2、cellStyle和cellClick方法实现

TypeScript 复制代码
<script lang="ts" name="" setup>
   const highlightedCell = ref(''); // 控制要高亮单元格标识
   // 单元格颜色
    const cellStyle = ({ row, column }: any) => {
	    if (highlightedCell.value && highlightedCell.value === JSON.stringify(row[column.property])) {
		     return {
			    padding: '5px 0',
			    backgroundColor: 'var(--el-color-primary-light-7)',
		     };
	     } else {
		     return {
			    padding: '5px 0'
		     };
	     }
    };
    // 点击单元格返回
    const cellClick = async (row: any, column: any, cell: any, event: any) => {
	    // console.log(row[column.property], row, column, '点击单元格返回');
	    highlightedCell.value = JSON.stringify(row[column.property]);
    };
    
</script>
相关推荐
东东51621 小时前
学院个人信息管理系统 (springboot+vue)
vue.js·spring boot·后端·个人开发·毕设
2601_9498683621 小时前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
m0_7482299921 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
xiaoxue..21 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
摘星编程21 小时前
在OpenHarmony上用React Native:自定义useHighlight关键词高亮
javascript·react native·react.js
2601_949613021 天前
flutter_for_openharmony家庭药箱管理app实战+用药知识详情实现
android·javascript·flutter
一起养小猫1 天前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
德育处主任Pro1 天前
『NAS』在群晖部署一款太空策略游戏-ogame-vue-ts
前端·vue.js·游戏
xcs194051 天前
前端 项目构建问题 \node_modules\loader-runner\lib\loadLoader.js
开发语言·前端·javascript
我爱加班、、1 天前
new Map()+Array.from()整理elementPlus的级联器数据
linux·前端·javascript