var avatarDownLoadUrlTemp=wx.getStorageSync('avatarDownLoadUrl')//获取头像的网络地址
var hasAvatarLocalUrl=false;
var qianImageDownloadUrlTemp=wx.getStorageSync('qianImageDownloadUrl')//获取签的网络地址
var hasQianImageLocalUrl=false;
// 获取头像的本地地址
wx.getImageInfo({
src: avatarDownLoadUrlTemp,
success:function(res){
that.setData({
avatarLocalUrl:res.path
})
hasAvatarLocalUrl=true;
}
})
// 获取签图片的本地地址
wx.getImageInfo({
src: qianImageDownloadUrlTemp,
success:function(res){
that.setData({
qianImageLocalUrl:res.path
})
hasQianImageLocalUrl=true;
}
})
// 后续代码是描述获取到avatarLocalUrl和qianImageLocalUrl后在本地画canvas
问题是:这两个getImageInfo函数都是异步函数,如何确保这两个异步函数都被执行完毕了再开始画canvas?求大神指导
wx.getImageInfo({ src: 'images/a.jpg', success(res) { wx.getImageInfo({ src: 'images/b.jpg', success(res) { //这里开始画canvas } }) } })
let p1 = new Promise((resolve, reject) => {
wx.getImageInfo({
src: 'images/a.jpg',
success(res) {
resolve('成功了a')
}
})
})
let p2 = new Promise((resolve, reject) => {
wx.getImageInfo({
src: 'images/b.jpg',
success(res) {
resolve('成功了b')
}
})
})
Promise.all([p1, p2]).then((result) => {
//开始画
console.log(result)
}).catch((error) => {
console.log(error)
})
感谢
尝试用 async/await 包装一下 wx.getImageInfo
能否写下示例让我学习一下
使用Promise.all