a标签的download属性,默认会直接打开新标签页显示pdf,如果想直接下载,可以将下面代码保存,
import Axios from 'axios'; function downloadURL(url, name) { const link = document.createElement('a') link.download = name link.href = url document.body.appendChild(link) link.click() document.body.removeChild(link) } function getFileName(url) { const name = url.split('/'); return name.pop(); } export function downloadFile(url, fileName = '', requestConfig = {}) { return Axios.get(url, requestConfig) .then(resp => { if (resp.status !== 200) { throw new Error('Download fail.') } else if (resp.blob) { return resp.blob() } else { return new Blob([resp.data]) } }) .then(blob => URL.createObjectURL(blob)) .then(url => { downloadURL(url, fileName) URL.revokeObjectURL(url) }) } export function downloadPdf(url, fileName='') { if(!fileName) { fileName = getFileName(url) } return downloadFile(url, fileName, {responseType: 'arraybuffer'}) // return downloadFile(url, fileName, {responseType: 'blob'}) }