vue中的ref,refs使用


使用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

------------------------------------------------------
作者:小牧臨風(一個懵懵懂懂的萌新碼農)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM