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
});

相关