get请求
function Download(path:any,params:any,name:any){
request.get(path,{param,responseType:'blob'})
.then(response=>{
let url=window.URL||window.webkitURL ||window
const link =document.createElement('a')
link.href=url.createObjectURL(new Blob([response]))
link.download=name
document.body.appendChild(link)
link.click()
})
}
post请求
function downLoadXlsx(url: string, params: any, fileName: string) {
return request(url, {
...params,
method: 'POST',
responseType: 'blob'
}).then((data) => {
const aLink = document.createElement('a');
const blob = data;
// const blob=new Blob([data], { type: 'application/vnd.openxmlformats-
// officedocument.spreadsheetml.sheet' });
aLink.style.display = 'none';
aLink.href = URL.createObjectURL(blob);
aLink.setAttribute('download', fileName); // 设置下载文件名称
document.body.appendChild(aLink);
aLink.click();
URL.revokeObjectURL(aLink.href); // 清除引用
document.body.removeChild(aLink);
});
}