问题描述
我正在尝试在我的 react 数组中下载数组中的图像。但它只下载一张图片。有人可以看看这个并说我哪里错了吗?
let fileDownloadHandler = async (pictures) => {
for (var i = 0; i < pictures.length; i++) {
forceDownload(pictures[i],'');
}
};
function forceDownload(url,fileName) {
var xhr = new XMLHttpRequest();
xhr.open('GET',url,true);
xhr.responseType = 'blob';
xhr.onload = function () {
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(this.response);
var tag = document.createElement('a');
tag.href = imageUrl;
tag.download = fileName;
document.body.appendChild(tag);
tag.click();
document.body.removeChild(tag);
};
xhr.send();
}
Pictures 是包含图片 url 的数组。它只下载一张图片。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)