Element el-tree 樹形的默認點擊第一個node,並高亮

<el-tree
  class="filter-tree"
  :data="treeData"
  :props="treeProps"
  node-key="id"
  :highlight-current="true"   //是否高亮當前選中節點,默認值是 false。把它設置爲true
  default-expand-all
  :filter-node-method="filterNode"
  ref="tree"
  @node-click="nodeClick">
</el-tree>

 

//後臺返回數據
commodityclasstwobyone(params).then((res) => {
            this.treeData = res.data
            if(res.data.length > 0 ){
              //'nextTick()' 下次dom更新時觸發回調函數
              //默認點擊
              this.$nextTick().then(() =>{
                const firstNode = document.querySelector('.el-tree-node')
                firstNode.click();
              })
            }
          })

 

$nextTick詳情 API

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章