我的邮戳"登录";在我的控制器中返回一个200。但我变得不确定了,我相信这是我的axios调用造成的。我知道控制台中的catch块报告了未定义的错误
Axios呼叫-
submit() {
let formData = new FormData();
formData.set("email", this.email)
formData.set("password", this.password)
formData.set("staySignedIn", this.staySignedIn)
// When the client/server sides are running from the same port (AWS) the url for this api call should be changed to /api/v1/login
axios.post("http://localhost:8080/api/v1/login", formData,
{headers: {'Content-Type': 'application/json'}})
.then(function (res) {
console.log(res); // test
if (res.data.code === 200) {
this.router.push('/dashboard')
console.log("success");
} else {
console.log(res.data.code);
}
})
.catch(function (err) {
console.log(err);
})
}
开发工具的响应
测试的响应
Axios响应模式文档在这里
除非您在控制器响应中有一个密钥code
,否则response.data.code
将是未定义的。
如果要检查HTTP状态,请尝试res.status
。
axios.post("http://localhost:8080/api/v1/login", formData,
{headers: {'Content-Type': 'application/json'}})
.then(function (res) {
if (res.status === 200) {
this.router.push('/dashboard')
console.log("success");
} else {
console.log(res.status);
}
})
.catch(function (err) {
console.log(err);
})
编辑您似乎正在将密码发送回响应中。即使密码是加密的,最好限制在响应中暴露它。