import request from "./axios"
// 地址、参数、文件名
downBlobFile(url, query, fileName) {
return request({
url: url,
method: "get",
responseType: "blob",
params: query
}).then(response => {
// 处理返回的文件流
const blob = response.data;
if (blob && blob.size === 0) {
alert("内容为空,无法下载");
return;
}
const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
window.setTimeout(function () {
window.URL.revokeObjectURL(blob);
document.body.removeChild(link);
}, 0);
});
}
前端文件下载 记录
于 2023-02-13 14:35:46 首次发布