这就是我所做的
在 Laravel 中
return Excel::download($report, 'coupons-report.xlsx');
在 Vue 中
async submitDates() {
await this.$axios({
url: "/exports/coupons?from=01-01-2020&to=30-03-2022", //your url
method: "GET",
responseType: "blob"
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "file");
document.body.appendChild(link);
link.click();
}); // Please catch me!
},
我的期望
- 下载了包含预期数据的 Excel 文件
实际发生的情况
- 一个包含 null 的文件。
注意:当我使用 Postman 并将响应保存为文件时,我得到了正确的结果。
最佳答案
我不确定这是否会对您有帮助,但这就是我使用 Laravel Excel 从 VueJS 组件下载文件的方法:
window.open("/exports/coupons?from=01-01-2020&to=30-03-2022").focus();
这将打开一个新窗口,下载文件,然后关闭。
关于laravel - 使用 VueJs 处理 Laravel Excel::download,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71705612/