之前有文章
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)