zoukankan      html  css  js  c++  java
  • vue 导出流文件excel

    第一种方法:需要设置响应类型,这里还需要安装 npm install js-file-download --save ,然后引用 var fileDownload = require('js-file-download'),使用详情见github;

    Vue.axios.post(url_post,params_post,{responseType: 'arraybuffer'}).then((res) => {
      let fileName = res.headers['content-disposition'].match(/fushun(S*)xls/)[0]; 
      fileDownload(res.data,fileName); 
    }).catch((res) => { 
      // 错误信息 
    })

    如果不添加 responseType: 'arraybuffer' ,那么下载下来的文件会提示已损坏

    第二种方法:需要设置响应类型,并用到Blob类型,了解Blob

    Vue.axios.post(url_post,params_post,{responseType: 'arraybuffer'}).then((res) => {
        
        let blob = new Blob([res.data], {type: "application/vnd.ms-excel"}); 
        let objectUrl = URL.createObjectURL(blob); 
        window.location.href = objectUrl;  
    
    }).catch((res) => {
        // 错误信息
    })
  • 相关阅读:
    树的重心备忘
    Hdu 2196
    HDU 1520
    TOJ1068 商务旅行
    携程HDU第一场1001
    USACO 4.3.2 The Primes
    Html常用标签的应用
    Html
    开班心得
    for循环练习及字符串处理
  • 原文地址:https://www.cnblogs.com/kdcg/p/9099455.html
Copyright © 2011-2022 走看看