在canvas绘制中,使用多张网络图片。由于downloadFile是异步操作,这时就需要Promise
来管理
let promise1 = new Promise(function(resolve,reject){
wx.downloadFile({
url: img1,
success:function(res){
console.log('downloadFile 图片1下载成功,path=' + res.tempFilePath);
resolve(res);
that.setData({
userIcon: res.tempFilePath
});
},
fail:function(res){
reject(res)
}
})
});
let promise2 = new Promise(function (resolve, reject) {
wx.downloadFile({
url: img2,
success: function (res) {
console.log('downloadFile 图片2下载成功,path=' + res.tempFilePath);
resolve(res);
that.setData({
userCode: res.tempFilePath
});
},
fail: function (res) {
reject(res)
}
})
});
let promise3 = new Promise(function (resolv