1 回复
可以试一下用promise来做:
const promixify = (api) => {
return (options, …params) => {
return new Promise((resolve, reject) => {
api(Object.assign({}, options, { success: resolve, fail: reject }), …params)
})
}
}
const getImageInfo = promixify(wx.getImageInfo)
const images = [‘img1.jpg’, ‘img2.jpg’, ‘img3.jpg’]
Promise.all(
images.map(img => getImageInfo({ src: img }))
).then((imageInfos) => {
console.log(imageInfos)
})