Force download GET request using axios

后端 未结 6 1698
生来不讨喜
生来不讨喜 2020-12-07 16:39

I\'m using vuejs 2 + axios. I need to send a get request, pass some params to server, and get a PDF as a response. Server uses Laravel.

So

axios.get(         


        
6条回答
  •  无人及你
    2020-12-07 17:21

    I tried some of the above suggested approaches but in my case the browser was sending me the popup block warning. The code described below worked for me:

    axios.get(url, {responseType: 'arraybuffer'})
       .then(function (response) {
         var headers = response.headers();
         var blob = new Blob([response.data],{type:headers['content-type']});
         var link = document.createElement('a');
         link.href = window.URL.createObjectURL(blob);
         link.download = "Your_file_name";
         link.click();
    });
    

提交回复
热议问题