描述
通过axios的post请求,下载excel文件
前端:
this.$http.post('/export-excel', {}, { responseType: 'blob' }).then(function (response) {
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = url
link.setAttribute('download', '导出报表.xlsx')
document.body.appendChild(link)
link.click()
})
后台:
public function exportExcel()
{
// 具体用法请参考 laravel-excel 文档
return Excel::download(new ExcelExport(), "导出报表.xlsx");
}
现状
本地开发导出excel乱码,postman模拟下载正常
问题
通过开发人员工具排除xhr请求是否通过mock.js发送,当Initiator为mock.js时excel乱码,Initiator为xhr.js时正常
删除或注释掉mock.js的引用,问题解决
原因
待查