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

}
相关推荐
CappuccinoRose13 小时前
拖拽交互体系
前端·javascript·css·html·交互·1024程序员节
开开心心就好13 小时前
免安装PDF盖章工具,透明度和位置可调
运维·服务器·前端·javascript·pdf·ocr·1024程序员节
风骏时光牛马13 小时前
AI服务线上推理异常故障
前端
king王一帅13 小时前
做了三年 ProseMirror 后,我用四个月自研排版引擎实现 WPS / Google Docs 替代品,整套框架 MIT 开源
前端·vue.js·开源
এ慕ོ冬℘゜15 小时前
如何在 HTML 中嵌入音频和视频?
前端·html·音视频
2501_944521591 天前
Ramda 跨端三方库仓颉适配全流程
开发语言·javascript·flutter·php
Ken_11151 天前
小体积附件下载正常,大附件下载异常
javascript
变与不变8061 天前
jQuery怎么使用
前端·javascript
神膘护体小月半1 天前
flex 布局的 order 属性
前端·css
paopaokaka_luck1 天前
流浪动物救助与收养系统(DeepSeek AI对话、 ECharts多维分析、救助流程衔接、领养与回访衔接、 捐赠确认与公示、志愿者协作)
java·前端·javascript·人工智能·mysql·echarts·推荐算法