Element组件的踩坑记录

el-tree

默认选中第一项

必须结合 current-node-key属性和this.$refs['treeRef'].setCurrentKey()方法及this.$nexTick()同时使用

 <el-tree
         ref="tree"
         accordion
         :data="departmentData"
         :props="defaultProps"
         :highlight-current="true"
          node-key="code"
          :current-node-key="this.currentNode.code"
          >
              <p class="tree-node" slot-scope="{node,data}">
                {{ data.name }}
              </p>
    </el-tree>
// 获取数据后设置默认选中值
this.$nextTick(()=>{
                this.currentNode = this.departmentData[0];
                this.$refs['tree'].setCurrentKey(  this.currentNode.code)
              })
posted @ 2022-05-20 15:15  DurianTRY  阅读(112)  评论(0编辑  收藏  举报