demand

The root node is selected by default for initialization, and the click node is selected for subsequent clicks

Train of thought

The value of current-node-key is set to the variable treeId, and the value of treeId is changed to automatically render

The specific implementation

HTML

<el-tree ref=”treeRef”

node-key=”id”

highlight-current

:current-node-key=’treeId’>

data

treeId: “0”

js

That.$nextTick().then(() => {// put this in the corresponding method. PS: Be sure to put it in nextTick !!!!! Otherwise it will not take effect

that.$refs.treeRef.setCurrentKey(that.treeId)
Copy the code

});