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
------------------------------------------------------
作者:小牧临风(一个懵懵懂懂的萌新码农)
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号