需求
初始化默认选中根节点,后续点击则选中点击节点
思路
current-node-key的值设置为变量treeId,改变treeId的值,自动渲染
具体实现
HTML
<el-tree ref="treeRef"
node-key="id"
highlight-current
:current-node-key='treeId'>
data
treeId: "0"
js
that.$nextTick().then(() => { // 将这个放在对应的方法里即可。PS:一定要放在nextTick里!!!!!否则不生效
that.$refs.treeRef.setCurrentKey(that.treeId)复制代码
});