要将查询字符串值作为整数发送,请使用qs库将请求数据序列化为URLEncoded格式,并在axios请求的config对象中设置“Content-Type”标头。
示例代码如下:
import axios from 'axios';
import qs from 'qs';
axios.post('/api/endpoint', qs.stringify({
id: 123,
name: 'John'
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});