国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

vue el-tree 默認展開第一個節點的實現代碼

瀏覽:2日期:2023-01-20 15:39:59

vue 的樹形控件 el-tree 可以用來方便地實現樹形控件,但是官方文檔中,關于控件的默認展開只有默認展開全部或者默認全部關閉,如下所示:

vue el-tree 默認展開第一個節點的實現代碼

對于指定節點的展開,需要指定其id,從而通過 default-expanded-keys 設置默認展開的節點。對于后臺返回的數據,默認展開其第一層的第一個,其實很簡單:對于獲取到的后臺數據,將其第一層節點添加到數組中,將 default-expanded-keys 綁定數組,從而設置默認展開的節點。實際應用:默認展開第一層節點中的第一個節點:

<template> <section> <!-- 機構類型編碼表 --> <el-row align='left'> <div class=’treeClass’> <el-tree :data='treeData' :props='defaultProps' @node-click='handleNodeClick' highlight-current node-key='id' :default-expanded-keys='treeExpandData'> </el-tree> </div> </el-row> </section></template><script>export default { data() { return { treeData:[], //后臺返回的tree樹列表 treeExpandData:[], //自己定義的用于接收tree樹id的數組 provincialCenterId:’’, defaultProps: { children: ’item’, label: ’name’, }, } }, created(){ this.getEquipmentList() }, methods: { // 獲取樹形結構默認展開節點 getRoleTreeRootNode(provincialCenterId) { this.treeExpandData.push(provincialCenterId) }, //獲取tree樹列表 getEquipmentList: function(params){ this.listLoading = true this.$api.ckApi.treeList({typeTag:true}).then((res)=>{ if(res.code==200){ this.treeData = res.resultDownload; this.provincialCenterId = this.treeData[0].id //默認展開第一個節點 this.getRoleTreeRootNode(this.provincialCenterId) this.listLoading = false }else{ this.$message.error(res) } }) }, }</script>

效果圖:

vue el-tree 默認展開第一個節點的實現代碼

總結

到此這篇關于vue el-tree 默認展開第一個節點的實現代碼的文章就介紹到這了,更多相關vue el-tree默認展開節點內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Vue
相關文章:
主站蜘蛛池模板: 深圳市| 台湾省| 潮州市| 溧阳市| 河南省| 大城县| 于田县| 栾城县| 朔州市| 若羌县| 读书| 宜兴市| 广宗县| 镇安县| 固阳县| 兴化市| 济宁市| 朝阳市| 白银市| 南召县| 河池市| 久治县| 江达县| 吕梁市| 临安市| 西丰县| 平远县| 右玉县| 舒城县| 大竹县| 木兰县| 西华县| 西华县| 武威市| 靖江市| 盐津县| 南涧| 辽阳市| 隆尧县| 栾城县| 元谋县|