vue如何判断图片已经加载完成?
Posted 醉笑三千席〆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue如何判断图片已经加载完成?相关的知识,希望对你有一定的参考价值。
const imgs = [
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\',
\'https://inews.gtimg.com/newsapp_bt/0/9906123226/1000\'
];
function ready(pics) {
const picsAll = pics.map((imgurl) => {
imgurl = imgurl + \'?v=\' + Math.random(); // 仅是为了区分下不同的图片链接
return new Promise((resolve, reject) => {
const img = new Image();
img.src = imgurl;
img.onload = () => resolve(imgurl);
img.onerror = () => reject(new Error(imgurl + \' load error\'));
})
});
Promise.all(picsAll).then(() => {
console.log(\'load all success\');
}).catch((e) => {
console.log(e);
})
}
以上是关于vue如何判断图片已经加载完成?的主要内容,如果未能解决你的问题,请参考以下文章