在Axios请求中添加请求体(data属性),如下所示:
axios.post('http://example.com', {
name: 'John',
age: 30
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
或者使用FormData对象来发送请求体,如下所示:
const formData = new FormData();
formData.append('name', 'John');
formData.append('age', '30');
axios.post('http://example.com', formData)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});