首先封装导出函数
// 导出
const downloadExcel = (response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
let fileName = response.headers['content-disposition'].split("filename*=utf-8''")[1]
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
}
发送请求获取文件
axios.get(exportUrl, { params: data, responseType: 'blob' }).then(res => {
downloadExcel(res)
})