在axios请求中加入responseType配置项,将其设为'arraybuffer',然后在响应拦截器中将返回的数据转成UTF-8字符串即可。
示例代码:
axios.get(url, {
responseType: 'arraybuffer'
}).then(response => {
const data = new TextDecoder('utf-8').decode(new Uint8Array(response.data));
// 处理数据
}).catch(error => {
console.error(error);
});