使用elementUI時,tree遇到的坑
1、
發現,this.$refs每次都是undefined;
問題原因:渲染組件需要時間,並且時間沒有JS執行的快;所以獲取不到
解決辦法:第一種利用setTimeout
this.condition = true;
setTimeout(()=>{
this.$refs.tree.setCheckedKeys(role.permissions)
},0)
2,
第二種:利用 this.$nextTick
this.condition = true;
this.$nextTick(()=>{
this.$refs.tree.setCheckedKeys(role.permissions)
})
PS:另外附上 setTimeout為0時的作用與意義 https://www.cnblogs.com/yhl-0822/p/9835588.html
------------------------------------------------------
作者:小牧臨風(一個懵懵懂懂的萌新碼農)