结构
<el-tree
ref="treeRef"
class="filter-tree"
:data="state.tableData.data"
:props="defaultProps"
:filter-node-method="filterNode"
highlight-current
@node-click="nodeClick"
default-expand-all
:current-node-key="state.currentLivingId"
node-key="organization_id"
:expand-on-click-node="false">
<template #default="{ node, data }">
<span>
<i v-if="node.level == 1" class="one_icon"></i>
<i v-else class="other_icon"></i>
<span> {{ data.label }} </span>
</span>
</template>
</el-tree>
<!-- 导航栏 -->
<p class="department-actions-navigation">
<div>{{ state.breadLabel }}</div>
</p>
自定义图标
根据el-tree判断级别,我这里的以及目录与二级目录图标不同
.one_icon {
background: url("../../../assets/img/organization.png");
width: 17px;
height: 14px;
display: inline-block;
background-size: 100% 100%;
margin-right: 10px;
}
.other_icon {
background: url("../../../assets/img/document.png");
width: 17px;
height: 14px;
display: inline-block;
background-size: 100% 100%;
margin-right: 10px;
}
操作点击显示导航栏
const state = reactive({
breadList: [],
breadLabel: "",
});
const nodeClick = (data) => {
state.breadList = [];
getTreeNode(treeRef.value.getNode(data.organization_id));
}
const getTreeNode = (node) => {
if (node && node.label) {
state.breadList.unshift(node.label);
getTreeNode(node.parent);
state.breadLabel = state.breadList.join(" > ");
}
};