使用axios下载文件流
作者:
回不去的那些时光 | 来源:发表于
2019-05-24 22:54 被阅读0次axios({
method: "post",
url: "你的url"
// 这里可以在header中加一些东西,比如token
})
.then(res => {
console.log("response: ", res);
// new Blob([data])用来创建URL的file对象或者blob对象
let url = window.URL.createObjectURL(new Blob([res.data]));
// 生成一个a标签
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
// 生成时间戳
let timestamp=new Date().getTime();
link.download = timestamp + ".pdf";
document.body.appendChild(link);
link.click();
})
.catch(error => {
console.log("response: ", error);
});
本文标题:使用axios下载文件流
本文链接:https://www.haomeiwen.com/subject/qrynzqtx.html
网友评论