不通过fetch
1、fetch(url)下载
可能会遇到跨域问题
fetch(url).then(res => res.blob().then(blob => {
var a = document.createElement('a');
var url = window.URL.createObjectURL(blob);
a.href = url;
if(materialName){
a.download = materialName;
}else{
a.download = filename;
}
a.click();
window.URL.revokeObjectURL(url);
}))
2、直接a标签
let a = document.createElement('a');
a.setAttribute('href', downloadUrl);
a.setAttribute('target', '"_blank"');
a.setAttribute('download', '');
a.click();
3、window.location.href= url