小程序callback not a function

操做:app

1. 若是是this.setData, 則更換this的指向,如:let _this = this
2. 在函數中經過參數回調時,會發現callback not a function, 則: -- 將回調函數放到this下,在經過先加載回調函數,就能夠了 ,如: // 選擇圖片
 chooseImg() { let that = this; wx.chooseImage({ success: function (res) { // 聲明回調函數和上傳選擇的圖片
        that.uploadImgCallback= function (uploadImgArr) { let arrImg = that.data.tpArrayImg.concat(uploadImgArr) wx.setStorageSync('imgList', arrImg) wx.navigateTo({ url: '/pages/editorPreview/editorPreview' }) } that.uploadImg(res.tempFilePaths) }, }) }, // 上傳圖片
 uploadImg(imgArr) { if (imgArr.length == 0) { return; } let that = this let imgSrc = imgArr.shift() wx.uploadFile({ url: app.globalData.host + '/album/saveImg', filePath: imgSrc, name: 'file', formData: { 'album': wx.getStorageSync('setText') ? wx.getStorageSync('setText').title : 'default', 'openid': wx.getStorageSync('openid') }, success: res => { that.data.uploadImgSrc.push(res.data) if (imgArr.length > 0) { that.uploadImg(imgArr) } else { that.uploadImgCallback(that.data.uploadImgSrc) } } }) },
相關文章
相關標籤/搜索