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>

效果如图
在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-26 07:56:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-26 07:56:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-26 07:56:04       87 阅读
  4. Python语言-面向对象

    2024-01-26 07:56:04       96 阅读

热门阅读

  1. 从Excel到BI你应该如何提BI需求

    2024-01-26 07:56:04       68 阅读
  2. .NET 2024 年 1 月更新|.NET 8.0.1、7.0.15、.NET 6.0.26

    2024-01-26 07:56:04       50 阅读
  3. Easyexcel的数据导入

    2024-01-26 07:56:04       51 阅读
  4. 【C语言】关于位运算符的简单运用

    2024-01-26 07:56:04       53 阅读