美文网首页
axios获取文件流并下载文件

axios获取文件流并下载文件

作者: 患者_ | 来源:发表于2020-05-12 10:29 被阅读0次
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);
})

给axios请求设置{responseType:'blob'}就可以接收文件流了

相关文章

网友评论

      本文标题:axios获取文件流并下载文件

      本文链接:https://www.haomeiwen.com/subject/ejgvnhtx.html