请求接口需要添加 responseType: ‘blob’
export function getOutExcelList(data){
return service({
url:'/xsxxJbxx/outExcel',
method:'post',
params:data,
responseType: 'blob',
})
}
js
exportF.value为后端需要的数据
async function saveExport() {
await getOutExcelList(exportF.value).then((res) => {
const link = document.createElement('a');// 创建a标签
let blob = new Blob([res.data],{type: 'application/vnd.ms-excel;charset=UTF-8'}); // 设置文件类型
link.style.display = "none";
link.href = URL.createObjectURL(blob); // 创建URL
link.setAttribute("download", "学生信息.xls");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
}