记录一下
直接下载
window.location.href = file.downloadUrl
根据url下载文件
fetch(/*url链接*/).then((res) => {
res.blob().then((blob) => {
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = '测评报告' + '.pdf1';
a.click()
window.URL.revokeObjectURL(url)
})
})
下载数据流文件
请求代码
axios({
method: "get",
url:'https://yingde_api.ydassess.com/health/report/download',
params: data,
responseType: 'blob',//必要
})
下载代码
let url = window.URL.createObjectURL(new Blob([data]));
let link = document.createElement("a");
link.style.display = "none";
console.log(url)
return
link.href = url;
link.setAttribute("download", "评测报告.pdf");
document.body.appendChild(link);
link.click();
来自 波澜之间
标签:文件,url,window,href,link,blob,下载 From: https://www.cnblogs.com/sundayRain/p/17771598.html