<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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐