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>

效果如图

相关推荐
Cobyte15 小时前
23.Vue Vapor 组件 attrs 的实现
前端·javascript·vue.js
触底反弹15 小时前
🚀 Node.js path 和 fs 模块,从回调地狱到 async/await 的进化之路!
javascript·后端·node.js
绝世唐门三哥16 小时前
vue3中页面返回时刷新首页的处理方案
开发语言·前端·javascript
sugar__salt16 小时前
Node.js path 与 fs 核心模块完全指南 —— 从路径处理到异步流程控制
javascript·node.js
柯克七七17 小时前
给老项目加了 TypeScript,本来只想自己爽,结果全公司代码审查标准被我抬高了
前端·vue.js·typescript
张元清17 小时前
React useObjectUrl Hook:预览文件与 Blob,不留内存泄漏(2026)
javascript·react.js
姑苏倾城客17 小时前
Flutter中,html 与 dart 桥接沟通
javascript·flutter·html
小粉粉hhh19 小时前
Node.js(五)——编写接口
前端·javascript·node.js
大意的百合19 小时前
Electron 应用如何上架微软商店:从 MSIX 打包到商店提交
javascript·microsoft·electron
自然 醒19 小时前
前端如何实现在线预览office常见文件功能?
前端·vue.js