Element-UI学习

Tree 树形控件

一键展开 / 折叠

定义按钮
1
2
<el-button plain type="success" @click="expandAll" size="mini">展开所有菜单</el-button>
<el-button plain type="warning" @click="collapseAll" size="mini">收起所有菜单</el-button>
定义展开 / 折叠方法
1
2
3
4
5
6
7
8
9
10
11
12
13
// 展开
expandAll() {
for (let i = 0; i < this.$refs.tree.store._getAllNodes().length; i++) {
this.$refs.tree.store._getAllNodes()[i].expanded = true;
}
},
// 折叠
collapseAll() {
for (let i = 0; i < this.$refs.tree.store._getAllNodes().length; i++) {
this.$refs.tree.store._getAllNodes()[i].expanded = false;
}
},

效果
一键展开折叠