在Axios请求中添加配置选项,禁用响应数据自动排序。示例代码如下:
axios.get('/api', {
params: {
id: 1,
name: 'John'
},
// 添加以下选项
paramsSerializer: function(params) {
return Qs.stringify(params, { arrayFormat: 'brackets', sort: false });
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
上述代码中,paramsSerializer
是一个函数,用于自定义参数序列化的过程。通过使用Qs.stringify
方法,并禁用sort
选项,我们可以禁止Axios对响应数据进行排序。
上一篇:Axios异步问题