el-tree expands or collapses all trees

Bind the attribute expanded. The tree has its own method this.$refs.tree.store.root.expanded. In the mounted method, assign expandAll = false to the tree method. The specific code implementation details are as follows:

html code:

<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 code:

data(){

return{
expanded:false
}

}

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

}

Guess you like

Origin blog.csdn.net/SYQ15544423296/article/details/131781863