<el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
:filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
@node-click="handleNodeClick">
<el-tooltip :disabled="showTitle" effect="dark" :content="tooltipTitle" placement="top"
slot-scope="{node,data}">
<span class="span-ellipsis" @mouseover="onShowNameTipsMouseenter">
{{ node.label }}
</span>
</el-tooltip>
</el-tree>
data() {
return {
tooltipTitle: "",
showTitle: true,
currentNodeId: "",
}
}
methods: {
onShowNameTipsMouseenter(e) {
var target = e.target;
let textLength = target.clientWidth;
let containerLength = target.scrollWidth;
if (textLength < containerLength) {
this.tooltipTitle = target.innerText;
this.showTitle = false;
} else {
this.showTitle = true;
}
},
}
::v-deep .el-tooltip {
color: black;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
white-space: nowrap;
}
.span-ellipsis {
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
}
el-tree 标题文本过长 设置鼠标经过显示全部文本
于 2024-07-19 15:45:38 首次发布