Q:elementUI中tree組件動態展開


1,在組件中設置展開收縮開關  default-expand-all="isExpand"

 2,展開收起觸發按鈕

<div class="tree-foot clearfix">
  <el-button class="fr" size="mini" plain type="primary" icon="el-icon-caret-top" @click="CloseFun">關閉</el-button>
   <el-button class="fr" size="mini" plain type="primary" icon="el-icon-caret-bottom" @click="ExpandFun">展開</el-button>
</div>

3,這里采用ref來獲取DOM。

// 展開收起
  ExpandFun(){
    console.log(this.$refs.navtree[0].store._getAllNodes().length)
    // let type = Object.prototype.toString.call(this.$refs.navtree)
    this.isExpand = true;
    this.DynamicScaling()
  }
  CloseFun(){
    this.isExpand = false;
    this.DynamicScaling()
  }
  DynamicScaling(){
      for(let j=0; j<this.$refs.navtree.store._getAllNodes().length; j++){
        this.$refs.navtree.store._getAllNodes()[j].expanded= this.isExpand;
      }
  }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM