【vue】解决element-ui的el-select下拉框中选项内容太长问题

实现效果:

1.给下拉框设置最大宽度;

2.内容一行展示,不换行,多余部分显示省略号;

3.有省略号的那一行,加悬浮提示;

4.没有省略号的地方不加悬浮提示


代码展示:

复制代码
<template>
  <el-select :popper-append-to-body="false">
    <el-option v-for = "item in dataList" :key = "item.value" :label = "item.label" :value = "item.value">
        <el-tooltip effect="light" :disabled="isShowTooltip" :content="item.label" placement="top">
          <div class="option-item" @mouseover="spanMouseenter($event)">
            {{ item.label }} 
          </div>
        </el-tooltip>
    </el-option>
  </el-select>
</template>
<script>
export default {
  data() {
    return {
      isShowTooltip: true,
    };
  },
  methods: {
    spanMouseenter(e) {
       let target = e.target
      if (target.clientWidth < target.scrollWidth) {
        this.isShowTooltip = false;
      } else {
        this.isShowTooltip = true;
      }
    },
  },
};
</script>
<style>
.option-item {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.el-select /deep/ .el-select-dropdown__item {
  max-width: 600px;
}
</style>
相关推荐
宁&沉沦1 分钟前
Cursor 科技感的登录页面提示词
前端·javascript·vue.js
Dragonir15 分钟前
React+Three.js 实现 Apple 2025 热成像 logo
前端·javascript·html·three.js·页面特效
武天26 分钟前
如果使用Vue3.0实现一个 Modal,你会怎么进行设计?
vue.js
古一|1 小时前
Vue3中ref与reactive实战指南:使用场景与代码示例
开发语言·javascript·ecmascript
peachSoda71 小时前
封装一个不同跳转方式的通用方法(跳转外部链接,跳转其他小程序,跳转半屏小程序)
前端·javascript·微信小程序·小程序
@PHARAOH1 小时前
HOW - 浏览器兼容(含 Safari)
前端·safari
undefined在掘金390412 小时前
flutter 仿商场_首页
前端
少卿2 小时前
react-native图标替换
前端·react native
熊猫钓鱼>_>2 小时前
TypeScript前端架构与开发技巧深度解析:从工程化到性能优化的完整实践
前端·javascript·typescript