downloadPdf(){
var ajax=new XMLHttpRequest();
ajax.open( "GET", "url地址", true);
ajax.setRequestHeader("Cache-Control","no-cache")
ajax.setRequestHeader('Access-Control-Allow-Origin', '*');
ajax.responseType = 'blob';
ajax.onload = e =>{
let res = e.target.response;
let blob = new Blob([res],{type: "application/pdf;charset=UTF-8"}) // 这里的res为后端返回的流数据
let aLink = document.createElement("a")
aLink.download = “xxxxx"// 下载文件的名字
aLink.href = URL.createObjectURL(blob)
aLink.click()
}
ajax.send()
}
PDF直接下载到本地vue
最新推荐文章于 2024-07-07 10:12:00 发布