欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

el-tree 全部展开和全部折叠

最编程 2024-05-19 19:02:03
...
<el-switch v-model="switchValue" @change="switchCheange" active-color="#13ce66" inactive-color="#ff4949"> </el-switch> <el-tree ref="treeRef" :props="props" :data="treeData" node-key="id" show-checkbox :default-checked-keys="defaultCheckedKeys" :default-expand-all="isExpand" @check-change="handleCheckChange"> // 这里default-expand-all不是响应式的,这行代码可以删掉,这里只做展示 </el-tree> switchCheange(){ this.isExpand = !this.isExpand let treeList = this.treeData; //关键代码 for (let i = 0; i < treeList.length; i++) { this.$refs.treeRef.store.nodesMap[treeList[i].id].expanded = this.isExpand; } }

推荐阅读