element el-tree current-node-key无效 setCurrentKey()无效

汤跃
2023-12-01

element el-tree current-node-key无效 setCurrentKey()无效

可以结合 current-node-key属性和this.$refs['treeRef'].setCurrentKey()方法及this.$nexTick()同时使用

代码如下

<el-tree
	ref="treeRef"
	node-key="id"
	:data="list"
	:current-node-key="currentKey"
><el-tree>

js:

created(){
	this.list=[数据]
	this.$nextTick(()=>{
		this.currentKey=this.list[0].id
		this.$refs['treeRef'].setCurrentKey(this.currentKey)
	})
}
 类似资料: