TypeError: Cannot read property '$router' of undefined
登录后尝试重定向时得到一个。我在路由器实例上尝试了各种方法,但根据控制台未定义?
登录操作(店内):
login({ commit, dispatch }, { username, password }) {
const querystring = require('querystring');
this.$axios.$post('connect/token', querystring.stringify({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
username,
password,
grant_type: 'password'
}))
.then(function (response) {
dispatch('setToken', {
token: response.access_token,
expiresIn: response.expires_in
});
this.$router.push({name: 'home' }); // this line is the issue
})
.catch(errors => {
console.dir(errors);
});
},