![](https://i-blog.csdnimg.cn/blog_migrate/26a3a0f46e2fc8344689ca1025337ee0.png)
<el-tree
ref="tree"
default-expand-all
highlight-current
check-on-click-node
node-key="id"
:data="treeData"
:props="defaultProps"
@node-click="nodeClick"
>
</el-tree>
treeData: [],
defaultProps: {
children: "children",
label: "columnName",
},
treeData: [],
async getTree() {
let obj = {};
await columnList()
.then((res) => {
if (res.data && res.data.length > 0) {
this.treeData = handleTree(res.data, "id");
obj = this.treeData[0];
this.$nextTick(() => {
// todo 在这里设置
this.$refs.tree.setCurrentKey(this.treeData[0].children[1].id)
})
} else {
this.treeData = [];
obj = {};
}
console.log("this.treeData", this.treeData)
})
.finally(() => {
console.log(obj);
this.nodeClick(obj);
});
},
created() {
this.getTree();
},
// 设置首行高亮效果
this.$refs.tree.setCurrentKey(this.treeData[0].id)