后台返回的数据格式

在这里插入图片描述
在这里插入图片描述

前端处理

$({
  method: "get",
  url: "/dafw/cljsdc",
  params: data,
  responseType: "blob" 设置接收数据的类型
}).then((res)=>{
const fileName = res.headers["content-disposition"].split("=")[1];
const _res = res.data;
let blob = new Blob([_res]);
let downloadElement = document.createElement("a");
let href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = fileName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
})
Logo

前往低代码交流专区

更多推荐