前端处理后端返回的文件流做导出操作

import { post } from 'axios';
// 导出
exportNoticeData() {
post(
'/safetyjapi/pic/gateWay/noticeExport',
{ ...this.entNameParams },
{
responseType: 'blob',
}
)
.then(res => {
if (res.status === 200) {
const blob = new Blob([res.data], {
type: 'application/ms-excel',
});
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = e => {
const a = document.createElement('a');
a.download = '公告栏.xls';
a.href = e.target.result;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
}
})
.catch(err => {
console.log(err.message);
});
},
posted @ 2020-06-19 17:07  聪明的笨小孩  阅读(5180)  评论(0编辑  收藏  举报