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