1.注意点
//JSON.parse() => 将数据转换为 JavaScript 对象
//JSON.stringigy() =>将 JavaScript 数组转换为 JSON 字符串
1.JSON.parse(JSON.stringify(this.user))
//规定传递的参数格式为json
2.'Content-Type':'application/json'
axios({
url: "http://localhost/user",
data: JSON.parse(JSON.stringify(this.user)),
method:"POST",
header:{
'Content-Type':'application/json'
}
}).then(res=>{
console.log(res.data)
})
本文介绍如何使用JSON.parse()和JSON.stringify()方法转换数据格式,并通过axios发送POST请求到HTTP服务器,同时确保了数据以JSON形式传递。
8996

被折叠的 条评论
为什么被折叠?



