代码:

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)就可以运行成功了

相关文章: