赞
踩
<el-tree
:data="deptOptions"
:props="defaultProps"
:expand-on-click-node="false"
:filter-node-method="filterNode"
ref="tree"
default-expand-all
highlight-current
@node-click="handleNodeClick"
/>
<div class="head-container">
<el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
:filter-node-method="filterNode" ref="tree" default-expand-all highlight-current
@node-click="handleNodeClick">
<template v-slot="{node}">
<span :title="node.label" class="node-label">{{node.label}}</span>
</template>
</el-tree>
</div>
.node-label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
function formatDeptOptions(deptOptions, maxLength = 13) {
for (let i = 0; i < deptOptions.length; i++) {
const node = deptOptions[i];
if (node.label.length > maxLength) {
node.label = node.label.slice(0, maxLength) + '...';
}
if (node.children && node.children.length > 0) {
formatDeptOptions(node.children, maxLength);
}
}
}
// 假设deptOptions已经存在并初始化完毕
formatDeptOptions(deptOptions);
console.log(deptOptions);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。