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直接请求…