【发布时间】:2021-03-18 16:36:46
【问题描述】:
我的控制器中的后映射“登录”返回 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);
})
}
【问题讨论】:
-
哪一行记录了未定义的内容?
-
@aksappy console.log(err) 和其他我可以告诉的
-
你能在这里添加一个错误,如果可以的话,请在 then 块的乞求时控制台记录状态码?
-
在你的 if 条件之前添加这一行 -
console.log(res)- 请告诉我们你得到了什么 -
@aksappy 在“测试响应”下完成。它回复了我的电子邮件和正确的(加密的)密码字符串
标签: javascript vue.js axios