axios 请求数据跳转页面报'$router' of undefined问题

代码:

this.$axios.post("/auth", {
'username': this.username,
'password': this.password
}).then(function (res) {
this.$router.push('/');
}).catch(function (error) {
console.log(error);
});

修改:

this.$axios.post("/auth", {
'username': this.username,
'password': this.password
}).then(function (res) {
this.$router.push('/');
}.bind(this)).catch(function (error) {
console.log(error);
});

在axios的请求后面加上.bind(this)就可以运行成功了

posted on 2019-09-29 16:15  瑾然  阅读(946)  评论(0编辑  收藏  举报

导航