流请求回来格式如下:
解决方式(避免下载文件打开后出现乱码)
export function windowOpen(url, fileName) {
axios({ // 用axios发送get请求
method: 'get',
url:url, // 请求地址
responseType: 'blob', // 表明返回服务器返回的数据类型
headers: {
'Content-Type': 'application/json',
'Authorization':'项目的token,可写可不写'
}
}).then(res => { // 处理返回的文件流
const blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
const elink = document.createElement('a');
elink.download = (fileName ? fileName : '_black')+'.xlsx';//下载文件名称
elink.style.display = 'none';
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
})
}