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

}
相关推荐
名字还没想好☜13 小时前
React 受控输入框光标跳到末尾:格式化输入时的 selection 丢失 bug 与修复
前端·javascript·react.js·bug·react·next.js
Access开发易登软件13 小时前
Access 怎么做前后端分离?用 Web API 读写 SQL Server
前端·数据库·人工智能·microsoft·excel·access
10share14 小时前
React 新一代样式隔离方案 —— 编译时、零运行时、原生写法
前端·react.js
upgrador14 小时前
桌面应用开发:Electron 与 NSIS 的关系、打包流程及 Windows 本地构建实战
javascript·windows·electron
Revolution6114 小时前
Node.js 是什么:前端项目里哪些事情由它完成
前端·面试·node.js
我要两颗404西柚14 小时前
Stage three:VUE工程化与实战工具
前端·javascript·vue.js
光影少年14 小时前
RN 的EventEmitter 双向通信
前端·react native·react.js
布鲁飞丝15 小时前
从零实现富文本编辑器#-浏览器选区与编辑器选区模型同步
java·前端·编辑器
写不来代码的草莓熊15 小时前
Cesium 地图交互绘制圆形、多边形
前端·javascript·地图
weixin_4277716115 小时前
前端版本检测
前端