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://127.0.0.1:40267/appservice/pages/add/add.js:412:14)
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://127.0.0.1:40267/appservice/__dev__/WAService.js?t=wechat&s=1643331694522&v=2.10.2:2:530772
at http://127.0.0.1:40267/appservice/__dev__/asdebug.js:1:48487
at C (http://127.0.0.1:40267/appservice/__dev__/asdebug.js:1:48142)
at http://127.0.0.1:40267/appservice/__dev__/asdebug.js:1:3205
at Set.forEach (<anonymous>)(env: Windows,mp,1.05.2111300; lib: 2.10.2)
网友回复
圣殿骑士:
this 对象作用域不对。。。
要么外部 let _this = this;
要么 箭头函数 res=>{}
Mr.Zhao:
success: res => {} 用箭头函数,两年了吧,这个问题才遇到?