elementui tree控件 設置默認選中並高亮第一行


 

 

 

 

 

 注意:一定要寫上this.$nextTick   否則不生效

      <el-tree
              ref="treeRef"
              :highlight-current="true"
              default-expand-all
              :data="architectureData"
              node-key="id"
              :current-node-key="currentNodekey"
              :props="defaultProps"
              @node-click="handleNodeClick"
            ></el-tree>



currentNodekey: "", //默認選中的節點樹 async treeByDept() { await treeByDept({}).then((res) => { this.architectureData = res.data; if (this.architectureData.length > 0) { this.currentNodekey = this.architectureData[0].id; this.$nextTick(() => { this.$refs.treeRef.setCurrentKey(this.currentNodekey); //一定要加這個選中了否則樣式沒有出來 }); } }); },



/* 點擊樹結構項的選中顏色 */
.el-tree--highlight-current .is-current.el-tree-node > .el-tree-node__content {
  background-color: #99ccff !important;
}


免責聲明!

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



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