axios jump page request data packets '$ router' of undefined issues

Code:

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

modify:

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

Behind the request axios plus .bind (this) can run a success

Guess you like

Origin www.cnblogs.com/zcpblog/p/11608483.html