1、需求:后端返回二进制文件流格式,如图在浏览器中展示
2、前端转换为所需文件
fetch(url, newOptions)
.then(res => res.blob())
.then(data => {
const downloadURL = window.URL.createObjectURL(data);
const a = document.createElement('a');
a.style.display = 'none';
a.href = downloadURL;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(downloadURL);
});
3、注意事项
请求头必须为:responseType: 'arraybuffer',