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>
相关推荐
QT 小鲜肉8 分钟前
【Linux命令大全】001.文件管理之file命令(实操篇)
linux·运维·前端·网络·chrome·笔记
羽沢311 小时前
ECharts 学习
前端·学习·echarts
LYFlied1 小时前
WebAssembly (Wasm) 跨端方案深度解析
前端·职场和发展·wasm·跨端
七月丶1 小时前
实战复盘:我为什么把 TypeScript 写的 CLI 工具用 Rust 重写了一遍?
前端·后端·rust
over6971 小时前
《闭包、RAG与AI面试官:一个前端程序员的奇幻LangChain之旅》
前端·面试·langchain
JIngJaneIL1 小时前
基于java+ vue交友系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·交友
苹果酱05671 小时前
解决linux mysql命令 bash: mysql: command not found 的方法
java·vue.js·spring boot·mysql·课程设计
拉不动的猪1 小时前
回顾计算属性的缓存与监听的触发返回结果
前端·javascript·vue.js
karshey2 小时前
【IOS webview】h5页面播放视频时,IOS系统显示设置的icon
前端·ios