通过递归判断node节点值来获取父祖级节点数据
<template>
<div>
<div>{{breadList}}</div>
<el-tree
ref="treeBox"
node-key="id"
highlight-current
default-expand-all
:data="data"
:props="defaultProps"
:expand-on-click-node="false"
@node-click="handleNodeClick">
</el-tree>
</div>
</template>
export default {
data() {
return {
breadList:[],
data: [{
id:1,
label: '一级 1',
children: [{
id:2,
label: '二级 1-1'
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
};
},
methods:{
handleNodeClick(node,data){
this.breadList = [];
this.getTreeNode(data);
},
getTreeNode(node){
console.log(node)
if (node) {
if (node.label !== undefined) {
this.breadList.unshift(node.label);
this.getTreeNode(node.parent);
}
}
}
}
};