Guest User

Untitled

a guest
Aug 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. const { data } = await axios.get('/api/admin/export-user', {
  2. headers: {
  3. 'Authorization': 'Bearer' + localStorage.getItem('token')
  4. },
  5. responseType: 'blob'
  6. });
  7.  
  8. let blob = new Blob([data], { type: "application/vnd.ms-excel" }),
  9. fileName = 'users.xls';
  10.  
  11. if (window.navigator && window.navigator.msSaveOrOpenBlob) { // for IE
  12. window.navigator.msSaveOrOpenBlob(blob, fileName);
  13. } else { // for Non-IE (chrome, firefox etc.)
  14. let a = document.createElement("a"),
  15. url = window.URL.createObjectURL(blob);
  16. document.body.appendChild(a);
  17. a.setAttribute('id', 'download-file');
  18. a.setAttribute('style', 'display: none');
  19. a.setAttribute('href', 'data:attachment/xlsx,' + url);
  20. a.setAttribute('download', fileName);
  21. a.click();
  22. window.URL.revokeObjectURL(url);
  23. document.querySelector('#download-file').remove();
  24. }
Add Comment
Please, Sign In to add comment