首先给axios设置 responseType:'blob'

下载方式:一、使用a标签下载

axios.post(url,data,{responseType:'blob'}).then(res => {
    const blob = new Blob([res.data]);//处理文档流
    const fileName = '资产列表.xlsx';
    const elink = document.createElement('a');
    elink.download = fileName;
    elink.style.display = 'none';
    elink.href = URL.createObjectURL(blob);
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href); // 释放URL 对象
    document.body.removeChild(elink);
})

下载方式:二、使用fileDownload插件下载

git地址:https://github.com/kennethjiang/js-file-download

 Axios.get(url, {
    responseType: 'blob',
  }).then(res => {
    fileDownload(res.data, '测试.xlsx');
  });

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-10-12
  • 2022-01-21
  • 2021-09-18
  • 2022-12-23
相关资源
相似解决方案