项目要求:
点击页面上的“拍照”按钮拍摄一张照片,然后将照片展示在页面上。
代 码:
<button bindtap=“chooseImage”>拍照</button>
<image src="{{src}}"></image>
Page({
data: {
src: “”
},
chooseImage: function () {
wx.chooseImage({
count: 1,
sizeType: [‘original’, ‘compressed’],
sourceType: [‘album’, ‘camera’],
success: function (res) {
var tempFilePath = res.tempFilePaths
this.setData({
src: tempFilePath[0]
});
}
});
}
});
问 题:
在开发工具中测试,点击“拍照”按钮,可以正常选择本机中的图片。
但图片选中后,<image>组件没有反应,并不展示选中的图片。查看开发工具的“调试”,显示:
WAService.js:3 thirdScriptError
this.setData is not a function;at pages/test1/test1 chooseImage function;at api chooseImage success callback function
TypeError: this.setData is not a function
………
求教!!!
………
sourceType: [‘album’, ‘camera’],
success: function (res) {
var tempFilePath = res.tempFilePaths;
var that = this;
that.setData({
src: tempFilePath[0]
});
}
………
依旧错误提示
WAService.js:3 thirdScriptError
that.setData is not a function;at pages/test1/test1 chooseImage function;at api chooseImage success callback function
TypeError: that.setData is not a function