前端通过blob文件流下载文件
前端下载方式有两种,一种是直接通过a标签下载
<a href="下载地址"></a>
第二种使用的就是blob文件流下载
其实就是把后端返回的二进制文件流放在Bolb里面,然后把blob创建成一个下载链接,
axios({ method: 'GET', url: '/api', params: params, responseType: 'blob' }).then(res=>{ let blob = new Blob([res.data], {type: "文件类型"}); let url = window.URL.createObjectURL(blob); window.location.href = url; }).catch(err=>{ console.log(err) })