结合Element ui实现
axiosExportHandle(url, body) {
const loading = this.$loading({
lock: true,
text: '导出中...',
spinner: 'el-icon-loading'
});
axios({
baseURL: window.CONFIG.baseUrl,
timeout: 300000,
url: url,
method: 'GET',
responseType:'blob',
data: body
}).then(res => {
const blob = new Blob([res.data], {type: res.data.type});
const fileName = decodeURIComponent(res.headers['content-disposition'].substring(20));
// 是IE >=IE10
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, fileName);
} else {
const objectURL = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = objectURL;
link.download = fileName;
link.click();
window.URL.revokeObjectURL(objectURL);
}
loading.close();
}).catch(e => {
loading.close();
this.$message.error(e)
});
}