Answer the question
In order to leave comments, you need to log in
How to download file on vuejs?
Hello. Interested in such a question, how can I download the file that generated me this package for laravel maatwebsite/excel.
I send a request with vue to the laravel controller which generates an excel file for me. The question is that I can’t, what should the method return so that I can then download this file?
Back and front of the project lie on different domains
Answer the question
In order to leave comments, you need to log in
Did not work with maatwebsite/excel package, but there is an example with phpexcel
let requestParams = {
method: 'get',
url: 'some-url',
responseType: 'blob',
};
axios.request(requestParams)
.then({data} => {
let filename = '123' + (Math.floor(Date.now() / 1000)) + '.xlsx';
let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
let link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
link.remove();
});
$oSpreadsheet = new Spreadsheet();
// TODO что-то делаем с $oSpreadsheet заполняем данными
$oWriter = IOFactory::createWriter($oSpreadsheet, 'Xlsx');
$sFilename = '123.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $sFilename . '"');
header('Cache-Control: max-age=0');
$oWriter->save('php://output');
exit;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question