<el-tree
ref="tree"
node-key="id"
:props="props"
:load="loadNode"
@node-click="nodeclick"
lazy
:key="treeKey"
>
</el-tree>
data() {
return {
treeKey: '', // 控制tree渲染的key
nodedata: "",
props: {
label: "structureName",
isLeaf: "leaf",
},
};
},
nodeclick(data) {
this.nodedata = data;
},
refreshNodeBy() {
//判断是否有父节点,如果没有就全部加载一遍数据
if (this.nodedata) {
let node = this.$refs.tree.getNode(this.nodedata.id); // 通过节点id找到对应树节点对象
if (node) {
node.loaded = false;
node.expand(); // 主动调用展开节点方法,重新查询该节点下的所有子节点
}
} else {
this.treeKey = +new Date();
}
},