检查请求的URL是否正确,同时确认服务器是否正常运行。如果URL和服务器均正常,可以尝试在请求头中设置Content-Type字段为'application/json',并将数据通过JSON.stringify()方法转换为JSON格式后发送请求,例如下面的代码:
axios({
method: 'POST',
url: '/api/user',
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
name: 'Tom',
age: 18
})
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})