vue前端下载后端返回的文件流

axios({
method: 'get',
url: url,
responseType: 'blob'
}).then((res) => {
console.log(res)
if (!res) {
return
}
let blob = new Blob([res.data], {
type: "application/octet-stream"
});
let url = window.URL.createObjectURL(blob)
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
document.body.appendChild(link)
link.click()
})

使用axios请求,封装的请求方法可能会导致返回的res变为字符串,从而出现解析失败,无法解析的问题,所以使用axios直接请求…
————————————————
版权声明:本文为CSDN博主「前端大王」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/l17606145618/article/details/106620206

原文地址:https://www.cnblogs.com/songjuntao/p/14579518.html