Skip to content

Instantly share code, notes, and snippets.

@LeoHeo
Created September 20, 2018 04:13
Show Gist options
  • Save LeoHeo/23298c2c44c45d87691970321aae3c5c to your computer and use it in GitHub Desktop.
Save LeoHeo/23298c2c44c45d87691970321aae3c5c to your computer and use it in GitHub Desktop.
axios로 excel 다운로드 할려고 할때 location.href가 아닌 progress bar 뜰 수 있게 하는 방식
axios.get(url, {
responseType: 'arraybuffer'
}).then(function (response) {
var blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
var blobURL = window.URL.createObjectURL(blob);
var tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', 'test.xlsx');
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment