elementUI el-tree报错 Cannot read property ‘setCheckedKeys’ of undefined"

给树节点赋值时,执行下面代码会报错,原因是:DOM元素未加载完成.

以下为错误写法。

handleRowClick(row) 
{    this.$refs.tree.setCheckedKeys(ids);  }
handleRowClick(row) 
{   
 this.$nextTick(() =>{     
 this.$refs.tree.setCheckedKeys(ids);
})

以上为正确写法,属于延迟回掉,但是也可能会报以上错误,还是在dom未加载完成。

SetTimeout(()=>{
this.$refs.tree.setCheckedKeys(ids);
})

 

posted @ 2022-06-22 16:41  zwbsoft  阅读(1035)  评论(0编辑  收藏  举报