打印出后端返回的数据:乱码了 前端
在前端请求的时候携带请求头responseType:blob,ios
axios({
method: 'GET',
url: '/api',
params: params,
responseType: 'blob'
}).then(res=>{
console.log(res)
let blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
let url = window.URL.createObjectURL(blob);
window.location.href = url;
}).catch(err=>{
console.log(err)
})
复制代码
携带请求头后,再次打印后端返回的数据,data为Blob对象了, axios
👍【注意】:后端
axios使用封装事后的请求设置请求头responseType:'blob'不生效,推荐你们使用axios({})的方式,不要使用如:axios.get()的方式api