vue:如果this.$refs.xxx报错访问不到

在标签里面写了个ref="table1",然后js里使用this.$refs.table1访问报错:Cannot read properties of undefined (reading '$refs')

 

 

解决办法:放到this.$nextTick(function(){});函数里使用,就可以访问到了

this.$nextTick(function(){
    console.log(this.$refs.table1);
    this.$refs.table1.lazy=true
});

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2022-03-27 18:04  下课后我要去放牛  阅读(1637)  评论(0)    收藏  举报