el-table在鼠标移动到单元格时变为下拉框,否则是普通文本

el-table将多个单元格改为下拉框,导致渲染卡顿,解决方法在鼠标移动到单元格时变为下拉框,否则是普通文本

复制代码
<el-table-column label="显示方向" width="150px" align="center" key="direction" prop="direction"
                         :show-overflow-tooltip="true">
          <template #default="{ row, $index }">
            <el-select v-if="row.showDropdown" v-model="row.direction" placeholder="请选择">
              <el-option v-for="item in directionList " :key="item.dictCode" :value="item.dictValue"
                         :label="item.dictLabel"></el-option>
            </el-select>
            <div v-else @mouseover="handleMouseOver(row)" @mouseleave="handleMouseLeave(row)" style="min-height: 20px;">
              {{ getLabelFromOptions(directionList, row.direction) }}
            </div>
          </template>
        </el-table-column>

js代码

复制代码
<script setup>
const directionList = ref([{ "dictCode": 1, "dictLabel": "左", "dictValue": "left"}, { "dictCode": 2, "dictLabel": "右", "dictValue": "right"},]);//显示方向

//鼠标移入下拉框
const handleMouseOver = (row) => {
  row.showDropdown = true;
};
//鼠标移出下拉框
const handleMouseLeave = (row) => {
  row.showDropdown = false;
};

//下拉框根据value获取label
function getLabelFromOptions(options, value) {
  const option = options.find(opt => opt.dictValue === value);
  return option ? option.dictLabel : '';
}
</script>

效果如图

相关推荐
默_笙6 小时前
🚦 请三个 AI 考官给 RAG 打分:量化评估实战(下)
前端·javascript
阿坨6 小时前
灵感闪存卡:一款 Tampermonkey用户脚本
javascript·tampermonkey
朝朝辞暮i8 小时前
C++ 第 25 课:getter / setter + this
java·javascript·c++
蜗牛互联网8 小时前
Python接入Gemini 3.8 Flash实现票据视觉抽取与规则校验
java·javascript·网络·人工智能·python
易朵朵9 小时前
CSS 格式化上下文
css·vue.js
xieter9 小时前
【技术精选】深入浅出现代前端渲染与性能优化实践指南 (2026-10-04)
前端·javascript
xieter10 小时前
【硬核实战】TypeScript Compiler API: Preserving Child Node Narrowing in Reusable Type Guards 🔧 (2026-10-03)
前端·javascript
xieter10 小时前
【硬核实战】React 19 useFormStatus Returning False? I Built a SubmitButton That Fixes It (2026-10-03)
前端·javascript
雪芽蓝域zzs11 小时前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
paopaokaka_luck11 小时前
非遗文物数字化小程序(AI非遗问答、ONNX图像识别、协同过滤推荐、ECharts数据分析、非遗知识浏览与互动、文创商城订单闭环、文化活动报名签到、社区交流)
javascript·spring boot·mysql·数据分析·echarts·mybatis