之前有文章
https://blog.csdn.net/qq_36120342/article/details/102455591
介绍如何实现Element-UI的菜单全部展开或全部关闭,但是这篇文章介绍的方法还额外需要未整理的树状原始数据,并且方法效率较低。这里我重新设计了函数,使用for语句直接遍历nodesMap对象,效率和便捷性都更高。
//设置全部展开和折叠。state参数为bool值
setAllExpand(state){
var nodes=this.$refs.tree.store.nodesMap
for(var i in nodes){
nodes[i].expanded=state;
}
},
调用方法:
this.setAllExpand(true)
或:
this.setAllExpand(false)