vue2.x 下载后台传过来的流文件(excel)后乱码问题

1.接口返回的流和头部:

 

2.下载流文件的代码

 

方法一:是用了插件 https://github.com/kennethjiang/js-file-download

方法二:是用了 blob

不管哪种方法,记得设置  responseType  !!!!!

 

附上代码:

//      导出订单
      exportBill:function () {

        let url_post = Vue.prototype.api.apiList.EXPORT_BILL;

        let params_post = {
          orderStartDate: this.timepickerDateFormat(this.rangeTime[0]) || this.rangeTime[0] || '',
          orderEndDate: this.timepickerDateFormat(this.rangeTime[1]) || this.rangeTime[1] || '',
          prodCode: this.prodId,
          promoteFlag: this.promotionSiteId,
          policyStatusList: this.tableBillStateCheckedData,
        };

        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);  //如果用方法一 ,这里需要安装 npm install js-file-download --save ,然后引用 var fileDownload = require('js-file-download'),使用详情见github;
      // let blob = new Blob([res.data], {type: "application/vnd.ms-excel"}); 

      // let objectUrl = URL.createObjectURL(blob);

      // window.location.href = objectUrl;

    }).
catch(function (res) {}); },

 

 

转载于:https://www.cnblogs.com/cynthia-wuqian/p/7927621.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值