網站首頁 編程語言 正文
本組件是對 Element UI 中 el-tooltip 組件的二次封裝
新增特性:鼠標移入父節點時,根據內容是否溢出判斷是否顯示 Tooltip
el-tooltip 文檔
<template>
<!--
屬性
content:el-tooltip 屬性,文本內容
effect:el-tooltip 屬性,Tooltip 主題,默認 light
placement:el-tooltip 屬性,Tooltip 顯示的方向,默認值為 top
-->
<el-tooltip :disabled="disabled" :content="content" :effect="effect" :placement="placement">
<span class="j-tooltip" ref="content">{{content}}</span>
</el-tooltip>
</template>
<script>
export default {
name: 'JTooltip',
props: {
content: String,
effect: {
type: String,
default: 'light'
},
placement: {
type: String,
default: 'top'
}
},
data() {
return {
disabled: false
}
},
mounted() {
const parentNode = this.$refs.content.parentNode;
parentNode.addEventListener('mouseenter', this.handleMouseenter);
},
methods: {
handleMouseenter(e) {
this.disabled = !this.textOverflow(e.target);
},
// 判斷文本是否溢出
textOverflow(element) {
const range = document.createRange();
range.setStart(element, 0);
range.setEnd(element, element.childNodes.length);
const rangeWidth = range.getBoundingClientRect().width;
const computed = window.getComputedStyle(element)
const padding = (parseInt(computed.paddingLeft, 10) || 0) + (parseInt(computed.paddingRight, 10) || 0);
return rangeWidth + padding > element.offsetWidth || element.scrollWidth > element.offsetWidth;
},
},
beforeDestroy() {
const parentNode = this.$refs.content.parentNode;
if (parentNode) {
parentNode.removeEventListener('mouseenter', this.handleMouseenter);
}
},
}
</script>
<style lang="scss" scoped>
.j-tooltip {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
原文鏈接:https://blog.csdn.net/dark_cy/article/details/124327055
相關推薦
- 2023-02-01 Python動態演示旋轉矩陣的作用詳解_python
- 2022-07-04 C#字符串String及字符Char的相關方法_C#教程
- 2022-07-12 微信小程序(條件渲染和列表渲染)
- 2022-11-21 小白也能看懂的Redis遍歷鍵和數據庫管理詳解_Redis
- 2023-01-31 Android數據存儲幾種方式講解_Android
- 2022-06-25 pycharm中venv文件夾自定義處理方式圖解_相關技巧
- 2022-06-19 Go中Writer和Reader接口的使用入門_Golang
- 2022-11-06 python分析inkscape路徑數據方案簡單介紹_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支