2

I am Doting Excel export using Laravel with Vuejs, somehow the Code is returning true value but can not Download Excel file, if I do normal request it will download the file, but in axios request, it will not export the file

I am using php artisan make:export to export file

In App/Export/studentexport.php

public function collection()
{
    return Student_master::all();
}

then in controller i will do a function

public function export()
{
    return Excel::download(new StudentExport, 'users.xlsx');
}

In my Vue file i will write a code that cal call the controller and export the file

axios.get('api/export')
            .then(()=>{
                toast({
                    type: 'success',
                    title: 'Export the Data'
                })
            })
            .catch(()=> {
                toast({
                        type: 'warning',
                        title: 'Can not Export'
                        })
            })

but the result is like that

that will return True, I really don't know how to solve this,plase help me

Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32
dhruvin prajapati
  • 184
  • 1
  • 3
  • 15

2 Answers2

3

I think is a little bit late but I had the same problem and I just solved it.

For download a file from vuejs, you shouldn't make the request as an Axios petition (at least not that I know). Instead, you can use a href and download attribute inside your template.

This is an example:

<a
    type="button"
    href="/api/export/entity/"
    download="file.xlsx"
>
    <button
        @click="export()"
        class="btn btn-primary"
    >
    Export
    </button>
</a>

The method helps if you need to do another stuff.

I hope this help you.

yurianxdev
  • 51
  • 7
2

ok I solve the problem, I use Vue-excel-export package that will Export the Excel File

enter link description here

this link can help me to install package and use it

dhruvin prajapati
  • 184
  • 1
  • 3
  • 15