h5 通过axios下载文件 适合各种文件类型

downloadFile(url , name , headers = {} , param = {}){
let paramAll = Object.assign({_cache:Date.now()} , param);
axios.get(url , {
headers,
responseType:'blob', // important
params:paramAll
}).then((response)=>{
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download',name);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
},

posted @ 2020-01-03 16:12  伟_少  阅读(764)  评论(0编辑  收藏  举报