скачать pdf используя axios - vuejs - PullRequest
0 голосов
/ 08 марта 2019

ОШИБКА получения ::

Uncaught (в обещании) TypeError: window.URL.createObjectURL не является функцией на eval
невозможно загрузить pdf

Мой код:

axios({                   
  url: url,                    
  method: 'GET',                    
  responseType: 'blob',                    
  headers: {                        
    'Authorization': 'Bearer ' +localStorage.getItem('token'),                        
  }                    
}).then((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();                    
});

бэкенд:

public function getPDF(Request $request) {        
    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1><center>Test</center></h1>');        
    return $pdf->download('invoice.pdf');            
}
...