網(wǎng)站首頁 編程語言 正文
本組件是對 Element UI 中 el-tooltip 組件的二次封裝
新增特性:鼠標移入父節(jié)點時,根據(jù)內(nèi)容是否溢出判斷是否顯示 Tooltip
el-tooltip 文檔
<template>
<!--
屬性
content:el-tooltip 屬性,文本內(nèi)容
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
相關(guān)推薦
- 2022-10-03 Python中不同圖表的數(shù)據(jù)可視化的實現(xiàn)_python
- 2022-04-23 es6實現(xiàn)數(shù)組對象深度去重
- 2022-05-25 python編碼問題匯總_python
- 2022-10-22 React實現(xiàn)pc端的彈出框效果_React
- 2022-03-29 在pyqt5中展示pyecharts生成的圖像問題_python
- 2022-12-23 Kubernetes應用配置管理創(chuàng)建使用詳解_云其它
- 2023-03-23 python跳出雙層循環(huán)的方法_python
- 2022-06-06 微信小程序動態(tài)綁定class
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支