zoukankan      html  css  js  c++  java
  • axios获取文件流并下载文件

    首先给axios设置 responseType:'blob'

    下载方式:一、使用a标签下载

    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);
    })
    

    下载方式:二、使用fileDownload插件下载

    git地址:https://github.com/kennethjiang/js-file-download

     Axios.get(url, {
        responseType: 'blob',
      }).then(res => {
        fileDownload(res.data, '测试.xlsx');
      });
    
  • 相关阅读:
    Mayan游戏
    选择客栈
    Redundant Paths
    中心选址
    辗转相除
    字符串
    线段覆盖
    配置魔药
    宝库通道
    教官的监视
  • 原文地址:https://www.cnblogs.com/lovecode3000/p/13900886.html
Copyright © 2011-2022 走看看