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>

效果如图

相关推荐
还有多远.39 分钟前
jsBridge接入流程
前端·javascript·vue.js·react.js
w2sfot1 小时前
Passing Arguments as an Object in JavaScript
开发语言·javascript·ecmascript
烛阴1 小时前
【TS 设计模式完全指南】从零到一:掌握TypeScript建造者模式,让你的对象构建链式优雅
javascript·设计模式·typescript
前端Hardy2 小时前
HTML&CSS:有趣的漂流瓶
前端·javascript·css
前端Hardy2 小时前
HTML&CSS :惊艳 UI 必备!卡片堆叠动画
前端·javascript·css
无羡仙2 小时前
替代 Object.freeze 的精准只读模式
前端·javascript
半花2 小时前
【Vue】defineProps、defineEmits 和 defineExpose
前端·vue.js
我的名字帅不帅2 小时前
使用 Element UI -Container 布局容器时监听屏幕滚动无效
vue.js
用户28003832908402 小时前
升级Vue3.4+版本,ant-design-vue 3.x 版本的Modal函数方式无法关闭问题
vue.js
小菜全3 小时前
uniapp新增页面及跳转配置方法
开发语言·前端·javascript·vue.js·前端框架