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[]) || this.rangeTime[] || '',
orderEndDate: this.timepickerDateFormat(this.rangeTime[]) || this.rangeTime[] || '',
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/)[]; 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) {}); },
vue2.x 下载后台传过来的流文件(excel)后乱码问题的更多相关文章
- js如何下载后台传过来的base64文件
一.<a>标签的作用 相信大部分人都知道<a>链接再简单不过了,跳转嘛,跳转到另外一个页面,这谁不知道. 当然这这是一部分, <a> 标签定义超链接,用于从一个页面 ...
- axios+post获取并下载后台返回的二进制流
axios+post获取并下载后台返回的二进制流 let url = $.getCookie('prefixUrl')+'/expenseword/exportWords'; let vm = thi ...
- go http 下载视频(TS码流文件)(推荐一个网站学习 go example)
视频 http下载代码 dn.go(注意:代码很ugly,没怎么花时间) 总体感觉特别简单,网上看了下 net/http ,io这2个库的使用, 几分钟就写完了,感觉cpp 在做工具这块 开发效率的 ...
- vue下载后台传过来的乱码流的解决办法
后台返回的乱码流 解决办法: 请求方式用的是axios,主要加关键的 {responseType: 'blob'} axios封装 export function postDownload(url, ...
- C#FTP操作类含下载上传删除获取目录文件及子目录列表等等
ftp登陆格式 : ftp://[帐号]:[密码]@[IP]:[端口] ftp://用户名:密码@FTP服务器IP或域名:FTP命令端口/路径/文件名 直接上代码吧,根据需要选择函数,可根据业务自己 ...
- vue 导出流文件excel
第一种方法:需要设置响应类型,这里还需要安装 npm install js-file-download --save ,然后引用 var fileDownload = require('js-file ...
- pdf流文件转图片
需求:将后台返回的pdf流文件转换成图片与页面其他内容一起打印pdf流文件不能直接在前台显示,需要借助pdf.js+viewer.js. 一般情况下,如果要打印pdf流文件,可以直接在新打开的view ...
- WP8.1 Study17:网络之后台下载/上传及HttpClient
一.后台下载/上传 1.简介 使用BackgroundTransferGroup可以十分方便操作上传及下载文件,BackgroundDownloader和BackgroundUploader类中的方法 ...
- 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传
[源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...
随机推荐
- HTML5 部分新增语义化标签元素
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 企业IT管理员IE11升级指南【12】—— 兼容视图列表介绍
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- \r,\n,\r\n的区别和用法
https://blog.csdn.net/xiaofei2010/article/details/8458605
- Spring的核心接口
ContextLoaderListener接口 Create a new ContextLoaderListenerthat will create a web application context ...
- [Swift]LeetCode169. 求众数 | Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- [Swift]LeetCode831. 隐藏个人信息 | Masking Personal Information
We are given a personal information string S, which may represent either an email address or a phone ...
- [Swift]LeetCode876. 链表的中间结点 | Middle of the Linked List
Given a non-empty, singly linked list with head node head, return a middle node of linked list. If t ...
- Python - Python2与Python3的区别、转换与兼容
区别 Python2.x与Python3.x版本区别:http://www.runoob.com/python/python-2x-3x.html 示例解读Python2和Python3之间的主要差异 ...
- TensorFlow tf.gradients的用法详细解析以及具体例子
tf.gradients 官方定义: tf.gradients( ys, xs, grad_ys=None, name='gradients', stop_gradients=None, ) Cons ...
- .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
本篇我将带着大家一起来对Dapper进行下封装并实现基本的增删改查.分页操作的同步异步方法的实现(已实现MSSQL,MySql,PgSQL).同时我们再实现一下仓储层的代码生成器,这样的话,我们只需要 ...