axios请求xsl表格文件流
需求
前端请求一个路径 来下载后台写的文件流
download() {
//axios 路径
excel('/a/b/c',{responeseType:'blob'}).then(res => {
var blob = new Blob([res], { type: "application/excel", endings: 'native' });
var link = document.createElement("a");
const fileName = "我的持仓.xls";
link.download = fileName;
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
}).catch(err => {
alert("下载失败!")
})
// download()
}