element的tree的高亮回显


需求是 在新建任务的时候,选中tree组件中的某条数据,在编辑这个任务的时候,通过后台的数据再次回显tree组件的选择的这条数据

<el-tree
      ref="tree"
      class="select-tree"
      highlight-current
     :data="options"
      :props="props"
      node-key="id"
      :expand-on-click-node="false"
      :filter-node-method="filterNode"
      @node-click="onClickNode"
      :default-expanded-keys="[1]"
    ></el-tree>
首先 highlight-current,node-key 属性要有
很简单的一句代码
 created() {
  // 回显tree的高亮
       this.$nextTick(()=>{
        this.$refs.tree.setCurrentKey(id)     // 此时的id就是之前你选中的数据对应的id
      })  
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM