开发微信小程序过程中,在一个回调函数中对js中的变量赋值时出现报错:Cannot read property 'setData' of undefined;at api chooseImage success callback function
代码如下:
wx.chooseImage({
count: 3,
sizeType: ['original'],
sourceType: ['album', 'camera'],
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths;
this.setData({
imgPaths:tempFilePaths
});
},
fail(err){
}
});
}
错误如下:
VM6263:1 thirdScriptError
Cannot read property 'setData' of undefined;at api chooseImage success callback function
TypeError: Cannot read property 'setData' of undefined
at success (http://127.0.0.1:43580/appservice/pages/comment/comment.js:42:14)
at Function.o.<computed> (WAService.js:1:1116874)
at Object.success (WAService.js:1:102889)
at r (WAService.js:1:418891)
at WAService.js:1:419068
at v (WAService.js:1:419077)
at WAServic