jeudi 7 mars 2019

pdf dowload using axios - vuejs

ERROR:: Uncaught (in promise) TypeError: window.URL.createObjectURL is not a function at eval

unable to download pdf

My code:

 axios({                   
                url: url,

                method: 'GET',

                responseType: 'blob', 

                // headers: {

                //     'Authorization': 'Bearer ' +localStorage.getItem('token'),

                // }

            }).then((response) => {

                console.log(response);

                const url = window.URL.createObjectURL(new Blob([response.data]));

                const link = document.createElement('a');

                link.href = url;

                link.setAttribute('download', 'file.pdf'); //or any other extension

                document.body.appendChild(link);

                link.click();

            });

backend:

public function getPDF(Request $request) {

    $pdf = App::make('dompdf.wrapper');    


    $pdf->loadHTML('<h1><center>Test</center></h1>');

    return $pdf->download('invoice.pdf');

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire