步骤主要分成两步
背景:我们在开发中将选中的文件id为识别码,在后端获取对应文件
1.创建辅助用的a标签,并且设置a标签不显示
<a id='download_help' style='display:none'>
2.typescript实现
private download(idList:any){
axios(
method:'post',
url:'...',
responseType:'blob',
headers:{'ContentType' : 'application/json'},
data:idList
).then((res:any)=>{
if(res.status==200){
// 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL
let url=window.URL.createObjectURL(res.data);
let elem:any=document.getElementById("download_helper");
elem.href=url;
elem.click();
// 告诉浏览器不需要继续保持url这个引用
window.URL.revokeObjectURL(url);
}
})
}