Axios.post(
api.getDustMonitorOverviewExport(
this.globalTenantId,
this.type,
this.id
), params, {
responseType: 'blob'
}
)
.then(res => {
debugger
const content = res.data;
const blob = new Blob([content], { type: 'application/ms-excel' });
let fileName = res.headers['content-disposition'].split('=')[1];
/* let Base64 = require('js-base64').Base64;
fileName = Base64.decode(fileName)*/
fileName = '扬尘监测统计列表.xlsx' || decodeURIComponent(fileName);
if ('download' in document.createElement('a')) {
// 非IE下载
const elink = document.createElement('a');
elink.download = fileName;
elink.style.display = 'none';
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
} else {
// IE10+下载
navigator.msSaveBlob(blob, fileName);
}
})
.catch(mes => {
console.log(mes)
})
一定要增加这个responseType: ‘blob’