【发布时间】:2018-02-12 13:09:37
【问题描述】:
好的,所以我有以下方法。基本上,我正在调用 API 后端,发布用户名和密码,如果通过,则在响应中,服务器会向我发送 200 状态。我想做的是在响应中,在我获得状态后,运行 if/else,所以如果状态为 200,则重定向,否则显示错误消息。每次我尝试使用 'this.$router.push('/any route here')',
我收到一个错误:'homepage.vue?3ec6:72 Uncaught (in promise) TypeError: Cannot read property '$router' of undefined'。
但是如果我在方法的顶部使用相同的路由,在 axios 调用之外,它工作正常。
那么我在这里错过了什么?
hero_login: function(event){
event.preventDefault();
axios.post('API call here',
{
service:'client',
user: this.user_email,
password: this.user_password,
json:true
})
.then(function(response){
const status =
JSON.parse(response.data.response.status);
console.log(status);
})
}
【问题讨论】:
标签: vuejs2 axios vue-router