/**
* @return {params} 文件流数据
*/
function download(params) {
//定义文件内容,类型必须为Blob 否则createObjectURL会报错
let content = new Blob([params]);
//生成url对象
let urlObject = window.URL || window.webkitURL || window;
let url = urlObject.createObjectURL(content, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
//生成DOM元素
let el = document.createElement('a');
//链接赋值
el.href = url;
el.download = 'todo文件导出.cvs';//cvs,xlsx文件名最好作为参数传入
//必须点击否则不会下载
el.click();
//移除链接释放资源
urlObject.revokeObjectURL(url);
}
axios请求拦截config.responseTyp设置
config.responseType = 'blob';
当进行 HTTP 请求时,可以通过配置 responseType 属性来指定响应的数据类型。responseType 可以设置为以下几种值:
arraybuffer:以 ArrayBuffer 形式接收响应数据。
blob:以 Blob 对象形式接收响应数据。
document:以 Document 对象形式接收响应数据。
json:以 JSON 对象形式接收响应数据。
text:以字符串形式接收响应数据。