el-tree 树全部展开或收起

绑定属性expanded,树自带方法this.$refs.tree.store.root.expanded,在mounted方法中给树方法赋值expandAll = false,具体代码实现详情如下:

html代码:

html 复制代码
<template>

      <el-tree
                  ref="tree"
                  :data="showDepData"
                  expand-on-click-node="false"
                  :props="{
                    label: 'name'
                  }"
                  node-key="deptId"
                  highlight-current
                  :default-expand-all="expanded"
                  @node-click="changeDepClick"
                >
                  <span slot-scope="{ node, data }">
                    <i
                      v-if="node.level == 1"
                      style="margin-right: 4px"
                      class="wk wk-customer"
                    />{{ data.name }}
                  </span>
                </el-tree>

</template

js代码:

java 复制代码
data(){

return{
expanded:false
}

}

mounted(){
//获取树自带的属性并给他赋值false
this.$refs.store.root.expanded = expanded

}
相关推荐
一个假的前端男1 天前
uniapp 3端轮播
前端·javascript·uni-app
Fantasydg1 天前
Request Response对象
前端
Wect1 天前
学习React-DnD:核心组件与Hooks
前端
humors2211 天前
前端开发案例(不定期更新)
前端·vue.js·elementui·ruoyi·若依
菠萝+冰1 天前
npm中-d -g 和默认安装的区别
前端·npm·node.js
心随雨下1 天前
Flutter Material 3设计语言详解
javascript·flutter·设计语言
一路向北North1 天前
网页版预编译SQL转换工具
前端·javascript·sql
拿不拿铁191 天前
Vite 5.x 开发模式启动流程分析
前端
fruge1 天前
设计稿还原技巧:解决间距、阴影、字体适配的细节问题
前端·css
把csdn当日记本的菜鸡1 天前
js查缺补漏
开发语言·javascript·ecmascript