el-tree 点击父级或者父级的checkbox,展开所有子集

<el-tree
                :data="authData"
                show-checkbox
                :check-strictly="true"
                :check-on-click-node="true"
                node-key="_id"
                ref="yourTreeId"
                @check-change="getCheckedKeys"
                highlight-current
               
                :props="defaultProps"
                :filter-node-method="filterAuthData"
                @check="handleCheck"
              >
              </el-tree>

  

 methods: {
    //点击父级展开所有子菜单
    handleCheck(data){
      let expandedData = this.$refs.yourTreeId.store.nodesMap;
       expandedData[data._id].expanded = true;
       if(data?.children?.length){ //有多少层子集,循环多少次
          data?.children?.map(obj=>{
            expandedData[obj._id].expanded = true;
            if(obj?.children?.length){
              obj.children.map(obj2=>{
                expandedData[obj2._id].expanded = true;
              })
            }
          })
       }
    },

}

  

posted @ 2022-04-14 18:26  江山一族  阅读(433)  评论(0编辑  收藏  举报