POST导出配置:
首先需要配置post请求的responseType为blob 返回的是文件流 代码如下:
export function exportUrl(data) {
return request({
url: '/animalCare/management/uploadPath',
method: 'post',
data: data,
responseType: 'blob'
})
}
POST获取文件流方式:
//导出数据
exportDataClick() {
let params = JSON.parse(JSON.stringify(this.queryParams));
exportUrl(params).then((blob)=>{
let reader = new FileReader();
reader.readAsDataURL(blob)
reader.onload = (e) => {
let a = document.createElement('a')
a.download = `doc_${new Date().Format('yyyy_MM_dd')}.xlsx`
a.href = e.target.result
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}
});
},
GET导出配置:
export let exportUrl = request.defaults.baseURL + '/animalCare/management/uploadPath';
GET打开文件方式:
window.open(exportUrl + id);