1,下载文件时接口返回流,相似下图
2,解决
dispatch({
type: 'newCardBin/download',
payload: { afsKey, fileName }
}, { responseType: 'blob' }).then((rsp) => { //须要制订responseType不然会呈现乱码,有效的话看下是否有mock.js文件,正文掉mock的引入
}) })
申请接口拿到rsp
let fileName = ‘1.xlsx’
const blob = new Blob([rsp]); //创立blob对象
const aLink = document.createElement('a'); //创立a链接
aLink.style.display = 'none';
aLink.href = blob;
aLink.download = fileName; //fileName也能够依据
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink); //点击实现后记得删除创立的链接
即可将流文件转化为 主动下载的文件
3,留神:fileName后缀要为.xlsx .docx等,如果简略命名可能会转为htm后缀文件
4,前端文件下载几种形式:https://blog.csdn.net/weixin_…
发表回复