axios 使用post请求下载文件

axios({
  url: '/custom/export',
  responseType: 'blob',
  method: 'post',
}).then( res
=> {   let blob = new Blob([res.data], {     type: 'application/vnd.ms-excel',
  });   let fileName = '定制合同.xlsx'   if (window.navigator.msSaveOrOpenBlob) {     navigator.msSaveBlob(blob, fileName)   } else {     var link = document.createElement('a')     link.href = window.URL.createObjectURL(blob)     link.download = fileName     link.click()     //释放内存
    window.URL.revokeObjectURL(link.href)   }
}).
catch(err => {   console.log(err); });

 

 

参考:https://blog.csdn.net/mobile18611667978/article/details/88988884

posted @ 2020-12-29 17:04  Mr_R  阅读(512)  评论(0编辑  收藏  举报