Force download GET request using axios

后端 未结 6 1697
生来不讨喜
生来不讨喜 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:00

    I don't think its possible to do this in axios or even AJAX. The file will be kept in memory, i.e. you cannot save file to disk. This is because JavaScript cannot interact with disk. That would be a serious security issue and it is blocked in all major browsers.

    You can construct your URL in front-end and download it in the following way:

     var url = 'http://example.com/order-results/' + id + '/export-pdf?' + '..params..' 
    
     window.open(url, '_blank');
    

    Hope this helps!

提交回复
热议问题