经测试,在安卓机,微信版本8.0.16中,传一个错误(不存在)的图片,例如:https://img10.360buyimg.com/evalpic/s230x230_jfs/t1/105296/37/16563/60906/5e7c7a68E86a9ae5c/d8a8682c300642ea.jpg!q80.webp
onerror事件不会执行
export function preLoadImg (url, canvas) {
return new Promise((resolve, reject) => {
if (canvas) {
const img = canvas.createImage();
img.src = url.replace(/\.webp/, '');
img.onload = () => resolve(img);
img.onerror = () => reject(img)
return;
}
wx.downloadFile({
url,
success: res => resolve(res.tempFilePath),
fail: reject,
});
return;
});
}