const load = async (imgSrc: string) => { return new Promise(resolve => { let image = new Image(); image.onload = () => resolve(image); image.onerror = () => resolve(null); image.src = imgSrc; }); }; // 预加载图片 export async function loadImage(imgSrcs: string | string[]) { if (typeof imgSrcs === "string") { await load(imgSrcs); } else if (Array.isArray(imgSrcs)) { await Promise.all(imgSrcs.map(async src => { await load(src); })) } }