<div class="tree-box">
<el-tree
ref="tree"
:data="loadCases"
show-checkbox
:check-on-click-node="true"
node-key="id"
highlight-current
:expand-on-click-node="false"
@check="handleCheckChange" // 用check可以获取到要用的属性
/>
</div>
handleCheckChange(datas) {
const data = this.loadCases[0].children;
const array = this.$refs.tree.getCheckedNodes();
// 获取选中的节点和半选中节点
const AllcheckedNodes = this.$refs.tree.getCheckedNodes(false, true);
// 选中的节点的索引
const chilIndex = AllcheckedNodes.findIndex(item => item.label === datas.label);
// 截取索引1 到 选中的之间的数据
const newAll = AllcheckedNodes.slice(1, chilIndex);
// 反转数据并拿到的第一个就是当前选中的父节点
const parent = newAll.reverse().find(item => item.children);
看了很多前辈的然后仔细研究了一下获取到的数剧所得到
我的数据结构比较简单只有两层,更深入的话,你们也可以试一下拿到的数据然后进行筛选过滤
喜欢就给个小花花哦