html
<el-tree
class="filter-tree"
:data="treeData"
:props="treeProps"
node-key="id"
:highlight-current="true"
default-expand-all
:filter-node-method="filterNode"
ref="tree"
@node-click="nodeClick">
</el-tree>
////是否高亮当前选中节点,默认值是 false。把它设置为true
javascript
commodityclasstwobyone(params).then((res) => {
this.treeData = res.data
if (res.data.length > 0) {
this.$nextTick().then(() => {
const firstNode = document.querySelector('.el-tree-node')
firstNode.click();
})
}
})
4、通过 typescript 来设置高亮显示的节点:
javascript
this.$nextTick(() => {
// selectId:绑定的 node-key
this.$refs.tree.setCurrentKey(selectId);
});