this.setData报错,网上搜索解决办法把this改成that还是报错是什么问题呢?

小程序 文章 2022-03-08 15:40 370 0 全屏看文

AI助手支持GPT4.0

this.setData报错,网上搜索解决办法把this改成that还是报错是什么问题呢?this.setData reports an error, what is the problem of changing this to that or reporting an error when searching for solutions on the Internet?

this.setData报错,网上搜索解决办法把this改成that还是报错是什么问题呢?

还有什么别的解决方法吗

Is there any other solution

回答:

圣殿骑士:

作用域的问题

写在 page({

onload:(){

let that = this; //写在外层,page里面的方法下

}

})

若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人

1:感谢!解决了
VBit:

你明白来this指的啥含义就明白为啥改成that,然后把that生命放在什么地方了

15:

let that = this; 写在最外层

吃鱼先生:

你wx.login外层的this指向已经不对了,所以你不管写啥箭头函数,写啥that都不行

จุ๊บ:

我猜你是在app.js 中使用 了setData

微喵网络:

你知道为什么要把this改成that吗?

1:因为success函数是闭包啊

-EOF-

AI助手支持GPT4.0