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方面里面监听默认选中的数组 在第一次赋值的时候默认调用点击按钮

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