axios的post请求下载excel以及文件乱码问题


描述

通过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的引用,问题解决

原因

待查


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM