步骤:
1、获取文件流;
2、用文件流创建url;
3、创建a标签,并自动点击
Download({
filename
})
.then(res => {
// console.log(res);
let link = document.createElement("a");
link.style.display = "none";
link.href = window.URL.createObjectURL(res.data);
//获取文件名称
let attachment = res.headers["content-disposition"];
let fileName = decodeURIComponent(
attachment.split(";")[1].split("=")[1]
);
// console.log(fileName);
link.download = fileName;
link.click();
window.URL.revokeObjectURL(link.href); //释放内存
})
.catch(err => {});