You must be familiar with axios calls for API consumption, but what about getting the files in response and render those files to the user for download. We got your covered, the below snippet is tested and works well.

  1. axios({
  2. url: 'http://api.dev/file-download',
  3. method: 'GET',
  4. responseType: 'blob', // important
  5. }).then((response) => {
  6. const url = window.URL.createObjectURL(new Blob([response.data]));
  7. const link = document.createElement('a');
  8. link.href = url;
  9. link.setAttribute('download', 'file.pdf'); //or any other extension
  10. document.body.appendChild(link);
  11. link.click();
  12. });

分类: web

标签:   vue   nodejs