//下载文件
axios({
method: "get",
url: baseURL + `/business/equipment/download`,
responseType: "blob",
params: {
panoId: val.id,
},
headers: {
Authorization: "Bearer " + getToken(),
},
}).then(function (response) {
console.log(response, "下载");
const link = document.createElement("a");
// 创建Blob对象, 固定写法
let blob = new Blob([response.data]);
// 设置元素样式不可⻅
link.style.display = "none";
// 创建下载链接
link.href = URL.createObjectURL(blob);
let contentDisposition = response.headers["content-disposition"];
// 获取⽂件名(后端应确保正确返回⽂件名)
const fileName = window.decodeURI(
contentDisposition.substring(contentDisposition.indexOf("=") + 1)
);
link.setAttribute("download", fileName);
// 加⼊dom树
document.body.appendChild(link);
// ⼿动触发点击事件
link.click();
// 移除之前创建的元素
document.body.removeChild(link);
// 释放Blob对象
window.URL.revokeObjectURL(link.href);
});```
vue文件流下载
最新推荐文章于 2024-05-08 18:20:36 发布