石家庄住房建设局网站,12306网站花多少钱做的,模版免费网站,环保网站 怎么做关于多张图片上传或者下载显示报错后会程序会终止执行#xff0c;从而影响后面图片上传。
解决方法#xff1a;
/*能正常访问的图片*/
const url https://2vimg.hitv.com/100/2308/0109/5359/dqKIZ7d4cnHL/81Vu0c.jpg?x-oss-processimage/format,webp;
/*不能正常下载的图…关于多张图片上传或者下载显示报错后会程序会终止执行从而影响后面图片上传。
解决方法
/*能正常访问的图片*/
const url https://2vimg.hitv.com/100/2308/0109/5359/dqKIZ7d4cnHL/81Vu0c.jpg?x-oss-processimage/format,webp;
/*不能正常下载的图片 跨域问*/
const urls https://p26-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/36b749b8bc954816b90998beef6a93e5~noop.image?_iz58558fromarticle.pc_detailx-expires1691135481x-signatureohziADdEWZ1qrfRqUI6xIitOnVk%3D;(function () {fetchFile(url, image);fetchFile(urls, images);})()async function fetchFile(url, fileName) {let promise new Promise(async function (resolve, reject) {// try {await fetch(url).then((response) response.blob()).then((blob) {const file new File([blob], fileName, {type: blob.type, lastModified: Date.now()})resolve(file);}).catch(error reject(error))// } catch (e) {// reject(e)// }})promise.then(/*请求成功*/function resolve(file) {const box document.getElementsByClassName(box1)box[0].src URL.createObjectURL(file);console.log(file)},/*请求失败报错*/function reject(error) {const box document.getElementsByClassName(box)box[0].src https://1vimg.hitv.com/100/2307/2810/1525/2WZw3cbDPP/bjgE99.jpg?x-oss-processimage/format,webpconsole.log(报错设置默认图片)console.log(error)})
}