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);
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17140232.html