Hello World...

axios POST 방식으로 파일 다운 받기 본문

vue.js

axios POST 방식으로 파일 다운 받기

FaustK 2022. 11. 18. 07:58

location.href 방식으로 다운로드를 받았는데,
axios post 방식으로도 받을 수 있다.

이 때는 response type을 blob 형식으로 받아야 한다.

https://www.npmjs.com/package/js-file-download
모듈을 사용하면 편하다.

https://stackoverflow.com/questions/41938718/how-to-download-files-using-axios


ex)
vue.js

 

 downloadList(payload) {
    // location.href = `/admin/getUserListExcel.do?${payload}`;
    return $axios.post('/admin/getUserListExcelPost.do', payload, { responseType: 'blob' });
  },

 

import fileDownLoad from 'js-file-download';

const file = await this.downloadList(payload);

fileDownLoad(file.data, 'UserList.xlsx');





Comments