h5 下载excel文件并实现通知

在ajax 返回实际上已经拿到了 服务端的数据 完成了数据的读取逻辑
fetch('http://localhost:8000/media/default/2023/02/45/\u519c\u5bb6\u4e50\u7533\u529e_ee8f4dde_5233.xlsx',{
  headers: {Authorization: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiOGRlMWM3ZjkxNjc3NDIxNjkxMDM0N2U4ZWM4NzMzNDkiLCJ0eXBlIjoiYWRtaW4iLCJyb2xlIjoxfQ.F5NXJPOdpd5g3SU1XfsFGs1bymzIuO2wjNooa1Hr_oA'},
})
  .then(response => response.blob())
  .then(res => {
      console.log(typeof res)
      const link = document.createElement('a');
     let blob = new Blob([res], {type: 'application/vnd.ms-excel'});
     link.style.display = 'none';
     link.href = URL.createObjectURL(blob);
     link.download = "plan.xlsx"; 
     document.body.appendChild(link);
     link.click();
     document.body.removeChild(link);
     console.log('下载成功')
     alert('下载成功')
  }).catch(console.error);
posted @ 2023-02-21 11:08  vx_guanchaoguo0  阅读(127)  评论(0编辑  收藏  举报