wx.getLocation({
type: 'wgs84',
success (res) {
this.setData({
latitude : res.latitude,
longitude : res.longitude,
accuracy : res.accuracy,
})
}
})
VM3449 WAService.js:2 thirdScriptError
Cannot read property 'setData' of undefined;at pages/add/add onLoad function;at api getLocation success callback function
TypeError: Cannot read property 'setData' of undefined
at success (http:
at Function.o.<computed> (http://127.0.0.1:40267/appservice/__dev__/WAService.js?t=wechat&s=1643331694522&v=2.10.2:2:1388831)
at Object.success (http://127.0.0.1:40267/appservice/__dev__/WAService.js?t=wechat&s=1643331694522&v=2.10.2:2:126419)
at y (http://127.0.0.1:40267/appservice/__dev__/WAService.js?t=wechat&s=1643331694522&v=2.10.2:2:528980)
at v (http://127.0.0.1:40267/appservice/__dev__/WAService.js?t=wechat&s=1643331694522&v=2.10.2:2:529218)
at http:
at http:
at C (http://127.0.0.1:40267/appservice/__dev__/asdebug.js:1:48142)
at http:
at Set.forEach (<anonymous>)(env: Windows,mp,1.05.2111300; lib: 2.10.2)
this 对象作用域不对。。。
要么外部 let _this = this;
要么 箭头函数 res=>{}
success: res => {} 用箭头函数,两年了吧,这个问题才遇到?