// 图片 url 地址
let urls = ['url1', 'url2'];
let promiseAll = [];
let imgs = [];
const len = urls.length
for (let i = 0; i < len; i++) {
promiseAll[i] = new Promise((res, rej) => {
imgs[i] = new Image();
imgs[i].src = urls[i];
imgs[i].onload = () => {
res(imgs[i]);
}
})
}
promise.all(promiseAll).then(img => {
// 加载完成后的代码
···
})
网友评论