Vue Router this.$router.push 不处理方法 [英] Vue Router this.$router.push not working on methods
本文介绍了Vue Router this.$router.push 不处理方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在登录,但在登录方法成功后,我正在为 $router
对象推送路由,但它不起作用,有人可以帮助我吗?
I'm doing login, but after the login methods gets success, I'm pushing a route for the $router
object and it's not working, can someone help me?
我的代码:
doLogin(){
this.attemptLogin({...this.user}).then(function(){
this.$router.push('/')
} )
},
因此,登录方法按预期执行,但回调 this.$router.push('/')
没有运行.
So, the login methods execute as expected, but the callback this.$router.push('/')
does not run.
我的attemptLogin
是一个动作,它的代码如下:
My attemptLogin
is an action, it's code is following:
export const attemptLogin = ( {commit}, user) => {
return http.post('login', {
'email': user.email,
'password': user.password
}).then(response => {
return commit(types.setToken, response.data)
}).catch( e => console.log(e))
}
推荐答案
您必须推送到名称或路径试试这个:
You have to push to a name or path Try this:
this.$router.push({ path: '/' })
this.$router.push({ name: 'Home' })
这篇关于Vue Router this.$router.push 不处理方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文