【发布时间】:2018-05-10 02:01:58
【问题描述】:
你好,我在尝试使用 Axios 和 VueJS 确认我从服务器收到的响应时遇到了一些问题
axios.post('/login', {
email: this.email,
password: this.password
}).then(response => {
if (response.status == 200) {
$root.$data.auth = true;
} else {
alert('uhhhh');
}
}).catch(e => {
if (e.response.status == 422) {
this.error = "You made that login right? How could you habve forgotten it!";
} else {
this.error = "Something else happened and this is what: " + e.response.status;
}
});
成功登录后,我会在控制台中看到:
Uncaught (in promise) TypeError: Cannot set property 'status' of undefined
Axios 文档指出我可以提取 response.status 对象并从中运行条件逻辑,这似乎令人困惑?
【问题讨论】:
-
报错说无法设置,这里你只是读取状态属性,你在哪里更新状态?
-
这也让这很奇怪,因为该组件中唯一提到的状态是试图读取该响应对象。 ://
-
你在代码的其他地方有没有声明
.status = something -
你能告诉我们发出异常的代码行吗?
-
if (e.response.status == 422) {这就是它在控制台中尖叫的地方。
标签: javascript json ajax vue.js axios