要使用Axios发送嵌套对象的POST请求,你可以使用Axios的post方法,并将嵌套对象作为请求的数据传递。
以下是一个使用Axios发送嵌套对象的POST请求的示例代码:
const axios = require('axios');
const data = {
name: 'John Doe',
age: 30,
address: {
street: '123 Street',
city: 'City',
state: 'State',
country: 'Country'
}
};
axios.post('https://example.com/api/endpoint', data)
.then(response => {
console.log('Response:', response.data);
})
.catch(error => {
console.error('Error:', error);
});
在上面的示例中,我们创建了一个嵌套对象data,其中包含一个address对象。然后,我们使用axios.post方法将数据发送到指定的URL(https://example.com/api/endpoint)。成功的响应将在then回调函数中进行处理,而错误(如果有)将在catch回调函数中处理。
请注意,这只是一个基本示例,你需要根据实际情况进行相应的调整,例如,将URL更改为你要发送请求的目标URL,并调整数据对象以符合你的需求。