1.vue-cli2+vue
注意:vue-cli2本地文件需要放在静态文件static下
<a href="javascript:void(0);" @click="download">帮助文档</a>
download(){axios.get('static/export.pdf', {responseType: 'blob', //重要}).then(response => {//判断是否是IE浏览器,是的话返回trueif ("msSaveOrOpenBlob" in navigator) {//兼容ie浏览器下载报传递给系统调用的数据区域太小.var data = response.data;var blob = new Blob([data], { type: "application/vnd.ms-excel" });window.navigator.msSaveOrOpenBlob(blob, '帮助文档.pdf');return;} else {const url = window.URL.createObjectURL(new Blob([response.data]));const link = document.createElement('a');let fname = '帮助文档.pdf';link.href = url;link.setAttribute('download', fname);document.body.appendChild(link);link.click();}});},
2.vue-cli3 +vue 参考此篇文章