Vue 给表格单元格加省略号和hover提示

基于antd vue的a-popover封装一下即可

js 复制代码
<template>
  <a-popover
    v-model="visible"
    trigger="none"
  >
    <template #content>
      {{ text }}
    </template>
    <div
      class="ellipsis"
      @mouseenter="onMouseenter"
      @mouseleave="onMouseleave"
    >
      {{ text }}
    </div>
  </a-popover>
</template>

<script setup>
import { defineProps, ref } from 'vue';

defineProps({
  text: {
    type: String,
    default: '',
  },
});

const visible = ref(false);

const checkOverflow = element => element.scrollWidth > element.clientWidth;

let cancelEnter = true;
let cancelLeave = true;

const onMouseenter = (e) => {
  cancelEnter = false;
  cancelLeave = true;
  setTimeout(() => {
    if (!cancelEnter) {
      visible.value = checkOverflow(e.target);
    }
  }, 100);
};

const onMouseleave = () => {
  cancelLeave = false;
  cancelEnter = true;
  setTimeout(() => {
    if (!cancelLeave) {
      visible.value = false;
    }
  }, 120);
};

</script>

<style lang="less">
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
相关推荐
deli0071 小时前
手机20%突然关机?电量百分比是估的,SOC曲线4组实测
前端
深蓝AI12 小时前
Meta 开源用了八年的设计系统 astryx:连坐两天 GitHub 总榜第一,组件库开始写给 agent 的说明书
前端·人工智能
ruanno_top12 小时前
轮播每 3 秒自己翻页:键盘停不下来,读屏也不知道换了页
vue.js
IT_陈寒12 小时前
Vue的watch把我坑惨了,原来要这样用才靠谱
前端·人工智能·后端
1-1=013 小时前
Vue 3 模板语
前端·javascript·vue.js
用户76103044737113 小时前
【转战智能眼镜开发】ROKID AIUI 小游戏 亚马逊标枪项目实战讲解
前端
风卿13 小时前
看着AI写代码太孤独了,来欣赏星云吧:一个DSH 装饰插件
前端·javascript
牧艺13 小时前
弹层不用再手算坐标了:CSS Anchor Positioning 从原理到可上线
前端·javascript·css
用户老李13 小时前
YOLO 目标检测自学教程 07:YOLOv3——多尺度预测
前端
moshuying14 小时前
ESP32 墨水屏金价牌(上):从点亮到把图片推过去
前端