如图片:
回调函数中的this执向不同
let that =this;
wx.chooseImage({
success:function(res){
wx.cloud.uploadFile({
//上传到云服务器的id
cloudPath:xx+'.png',
//上一个chooseImage的成功回调函数返回结果中的文件暂时路径
filePath:res.tempFilePaths[0],
success:function(res2){
res2.fileID;获取上传文件的id,可直接使用
})
},
fail:function(){xxx}
})
代码示例:
uploadEvent(){
let that=this;
wx.chooseImage({
success: function(res) {
console.log(res);
//将选中的图片上传到云服务器
wx.cloud.uploadFile({
//上传到云服务器的id
cloudPath:new Date().getTime()+'.png',
//上一个chooseImage的成功回调函数返回结果中的文件暂时路径
filePath:res.tempFilePaths[0],
success:function(res2){
console.log(res2);
let arr=that.data.imgSrc;
arr.push(res2.fileID);
that.setData({
imgSrc: arr
});
}
})
},
fail:function(res)
{
console.log('error');
}
})
}
})