export const downloadFile = {
data() { },
methods: {
async downloadFile(downRes) {
const downloadLinks = downRes.data.data;
for (const item of downloadLinks) {
const xhr = new XMLHttpRequest();
xhr.open('GET', item.url, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status === 200) {
const blob = xhr.response;
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = item.sourceDocumentName; // 设置下载的文件名为指定的名字
link.click();
window.URL.revokeObjectURL(url);
}
}
xhr.send();
}
}
}
}
封装成公共组件。