<!--
* @Descripttion:
* @version:
* @Author: Xueran
* @Date: 2022-10-25 21:48:41
* @LastEditors: Xueran
* @LastEditTime: 2022-10-25 21:56:01
-->
<template>
<el-tooltip
:content="value !== null ? value + '' : '-'"
:disabled="tooltipShow"
placement="top-start"
>
<div :class="style.parentBox" @mouseover="isShowTooltip">
<span ref="content" >
{{ value }}
</span>
</div>
</el-tooltip>
</template>
<script>
import style from './index.module.css';
export default {
name: 'DescriptionsTooltip',
props: ['value'],
data() {
return {
style,
tooltipShow: false
};
},
methods: {
isShowTooltip() {
const bool =
this.$refs.content.offsetWidth <
this.$refs.content.parentNode.offsetWidth;
this.tooltipShow = bool;
}
}
};
</script>
注意: 外面的盒子需要包起来 并且要有个固定宽度
<div class="value">
<descriptions-tooltip :value="你绑定的变量 || '-'" />
</div >
.value {
外盒子的宽度需要固定
}
.parentBox {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
判断内容是否超出 超出省略并且鼠标hover出现tooltip
于 2024-02-19 17:35:16 首次发布