目录

Vue-前端发送请求,后端接收到数据为null

目录

Vue 前端发送请求,后端接收到数据为null

原代码:

login() {
this.$axios
.post("/api/user/login", this.user)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error("登录失败:", error.response.data);
});
}

尝试了各种方法,qs.stringify()、配置请求头等等都没用,最后修改代码如下成功解决问题。

login() {
this.$axios
.post("/api/user/login", {
id: this.user.account,
password: this.user.password,
})
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error("登录失败:", error.response.data);
});
}