<el-tree
    node-key="id"     //设置以id作为key
    :current-node-key="currentLivingId"   //设置当前选中节点的key
    :data="deptOptions"
    :filter-node-method="filterNode"
    ref="tree"
    default-expand-all
    highlight-current
    :expand-on-click-node="false"
    @node-click="handleNodeClick"
 />
getTreeselect() {
  treeselect().then(response => {
    this.deptOptions = response.data;
    //设置当前选中的key
    this.currentLivingId = response.data[0].id;
    //把当前选择的key设置到el-tree中
    this.$nextTick(function () {
      this.$refs.tree.setCurrentKey(this.currentLivingId)
    })
  });
},
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐