vue el-tree初始化的時候默認選中第一個

 el-tree初始化的時候默認選中第一個

先查看https://cloud.tencent.com/developer/section/1489888按照以上方法能不能解決

首先設置node-key 

然後設置default-expanded-keys

<template>
  <div class="system-tree">
    <el-tree :data="data" node-key="id" :props="defaultProps" lazy :default-expanded-keys="expandDefault" 
     ref="orgTree"
    :load="loadOrgUserTree" @node-click="handleNodeClick">
    </el-tree>
  </div>
</template>

在data裏面第一默認選中的key

在method方法裏面的load方法給默認的數組賦值, 

在load

  watch: {
     'checkDefault':function(newVal, oldVal) {
       if(newVal){
         this.$nextTick(() => {
              document.querySelector('.el-tree-node__content').click()
          })
       }
     }
  },

在watch方面裏面監聽默認選中的數組 在第一次賦值的時候默認調用點擊按鈕

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