我正在尝试通过在我的 Vue 项目中发送 Api 请求来下载文件,并且我正在尝试使用 blob 和 FileSaver.js 保存响应数据
sendAjaxCall.then(response => {
let file = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
FileSaver.saveAs(file, 'Export2.xlsx')
}
但我无法打开文件,它已损坏。
最佳答案
试试这个
return Vue.axios.get(`api/excel_sheet`, {
responseType: 'blob',
}).then(response => {
FileSaver.saveAs(response.data, 'Export2.xlsx')
};
你需要指定响应类型为blob
关于javascript - 在 vue 项目中使用 blob 和 FileSaver.js 下载 excel(.xlsx) 已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48181594/