效果如上图↑
// 折叠所有节点
foldAllNodes(type) {
let treeNodes = this.$refs[type + '_tree'].store._getAllNodes()
for (var i = 0; i < treeNodes.length; i++) {
treeNodes[i].expanded = false;
}
},
// 展开所有节点
expandAllNodes(type) {
let treeNodes = this.$refs[type + '_tree'].store._getAllNodes()
for (var i = 0; i < treeNodes.length; i++) {
treeNodes[i].expanded = true;
}
},
然后务必在
<el-tree
...
node-key="id" //加入这个属性,否者代码无法生效
...
</el-tree>