element ui el-tree组件 首项选中效果

默认首项选中效果

 dom层,

指定key(业务id),ref="tree",highlight-current-row,:highlight-current="true"属性加上

el-tree(
    :data="typeArr",
    ref="tree",
    :highlight-current="true",
    highlight-current-row,
    node-key="equipTypeId",
    @node-click="handleNodeClick",
    default-expand-all,
    :expand-on-click-node="false"
)

script层

setCurrentKey,设置首项的业务id 
watch: {
    "$store.state.devMng.devType": function (n) {
           this.typeArr = n;
       this.$nextTick(() => {
         this.$refs.tree.setCurrentKey(n[0].equipTypeId);
       });
    },
},

这样就好了

希望可以帮到你,我是金陵彭于晏,我们下篇博客见!!!

原文地址:https://www.cnblogs.com/lq2333/p/14982476.html