首先在发请求的时候就需要加一个参数
this.axios({url:'url',responseType: 'blob'}).then(res=>{
this.downloadFile(res, '导出.zip')
})
下载固定的方法
downloadFile(
file,
fileName,
fileType = "application/octet-stream;charset=UTF-8"
) {
if (!file) return false;
const blob = new Blob([file], {
type: fileType,
});
// 非IE
if ("download" in document.createElement("a")) {
const link = document.createElement("a");
const href = URL.createObjectURL(blob);
link.href = href;
link.style.display = "none";
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
// 下载完成进行释放
URL.revokeObjectURL(href);
document.body.removeChild(link);
} else {
// ie10+
window.navigator.msSaveBlob(blob, fileName);
}
},