el-tree刷新时会初始化绑定数据,可设置el-tree的默认展开节点,还原刷新前展开状态
:default-expanded-keys="defaultExpandNodes"
在调用el-tree绑定数据刷新时执行一下方法保存当前节点展开状态即可
setDefaultExpandedKeys() {
let treeCompInstance = this.$refs["tree"];
let allNodes = treeCompInstance.store._getAllNodes();
let defaultExpandNodes = [];
allNodes.forEach((node) => {
node.expanded && defaultExpandNodes.push(node.data.subId);
});
this.defaultExpandNodes = defaultExpandNodes;
},