后端返回文件流类型,前端下载要进行处理,处理代码如下:
import request from '@/router/axios';
//将后台返回的文件流做处理,导出excel
exportSearchList(url,name,params,time,type) {
request({
method: type,
url: url,
data:params,//post请求
// params,//get请求
responseType: "arraybuffer"
}).then(function(res){
console.log("返回的二进制流文件", res)
if(!res) return;
//fileName:下载的文件名
// let currentData=timeFormat(new Date())
var fileName = name+time
let blob = new Blob([res], {type: 'application/vnd.ms-excel;charset=utf-8'});
// 针对ie浏览器
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {