vue下载本地pdf文件
Vue下载本地pdf文件html:<button @click="downloadPDf">downloadPDf</button>js:downloadPDf() {axios.post('http://localhost:8080/static/test.pdf', {responseType: 'blob'...
·
Vue下载本地pdf文件
html:
<button @click="downloadPDf">downloadPDf</button>
js:
downloadPDf() {
axios.post('http://localhost:8080/static/test.pdf', {
responseType: 'blob', //重要
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
let fname = 'report.pdf';
link.href = url;
link.setAttribute('download', fname);
document.body.appendChild(link);
link.click();
})
}
}
记住本地文件一定要放在static文件夹下面。
更多推荐
已为社区贡献3条内容
所有评论(0)