一、出现原因:
向后端发送请求时,由于前端未对发送的数据进行序列化,导致后端无法识别
序列化后的形式(键值对的形式):
{"username":"user","email":"user@168.com","dept":{"id":7},"nickName":"user"}
解决方法:JSON.stringify(data)
this.$request.put('url:xxx',JSON.stringify(resultObj),
{
headers: {
'Content-Type': "application/json;charset=UTF-8"
},
}).then((res) => {
console.log(res)
console.log('修改请求发送完成')
this.refreshTable()
})
二、JSON.stringify(data)与JSON.prase(data)的区别
前者data是对象,后者data是字符串