1.添加ajax请求(responseType:'blob',)
const exportExcelApi = (options)=>{
return fetchPost(IP+'/airport/downExcel', {body:options,responseType:'blob',});
}
2.请求到流下载到本地
const down = (type,response)=>{// 创建隐藏的可下载链接 response.data是返回的二进制流 根据后台返回的数据const url = window.URL.createObjectURL(new Blob([response.data])); //const link = document.createElement('a');link.href = url;console.log(url,"url")link.setAttribute('download', type+'.xlsx'); // 自定义文件名document.body.appendChild(link);// 模拟点击下载link.click();// 清除无用的URL对象window.URL.revokeObjectURL(url);link.remove();}