需求:树形菜单点击之后需要形成面包屑,所以需要当前节点和其父级节点的数据。记录一下解决方法,如下。
<el-tree
style="height:calc(100vh - 180px)"
ref="tree"
icon-class="el-icon-caret-right"
:data="dataTree"
:props="{label:'groupName',children:'groups'}"
node-key="key"
@node-click="TreeCk"
> <!-- :expand-on-click-node="false" -->
</el-tree>
TreeCk(e){ //树节点点击
let tree:any = this.$refs.tree;
this.treeKey = ''; //初始化
this.breadList = []; //初始化
if (!e.groups){
this.getTreeNode(tree.getNode(e.key));
this.treeKey = e.key;
this.treeGroupType = e.groupType;
this.getData();
}
}
getTreeNode(node){ //获取当前树节点和其父级节点
if (node) {
if (node.label !== undefined) {
this.breadList.unshift(node.label); //在数组头部添加元素
this.getTreeNode(node.parent); //递归
}
}
}
this.breadList。可以得到当前节点和其父级的lable数组集合。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有