<a href="...pdf?response-content-type=application/octet-stream" download target="_blank"></a>
1、a标签中添加download属性,但是这个方法有时候会失效,这是因为download不支持跨域请求,网站和pdf文件必须在同一域名下才可行,不然就是先打开一个新标签预览
2、在pdf文件下载链接后加response-content-type=application/octet-stream,在浏览器中打开pdf文件链接时,浏览器会默认进行下载
3、动态创建a标签进行下载
let url = data.url+'?response-content-type=application/octet-stream';// data.url路径地址
downloadFile(url)
function downloadFile(url) {
//下载文件
let a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("download",'download');
a.setAttribute("target", "_blank");
let clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent("click", true, true);
a.dispatchEvent(clickEvent);
}