好的,所以我有以下方法。基本上我正在调用API后端,发布用户名和密码,如果这些通过,在响应中,服务器发送给我200状态。我想做的是,在响应中,在我获得状态后,运行if / else,所以如果状态为200,则重定向,否则显示错误消息。每次我尝试使用'this。$ router.push('/ any route here')',
我收到一个错误:'homepage.vue?3ec6:72 Uncaught(in promise)TypeError:无法读取未定义的属性'$ router'。
但是如果我在方法的顶部使用相同的路径,在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);
})
}