我正在尝试使用nuxt-i18n中的localRoute方法
this.$router.push(this.localeRoute({ name: "home" }))
我试过这种方法,但是不起作用,正确的方法是什么呢?
发布于 2021-04-10 00:36:40
在vuex中,this.localRoute或this.localPath是未定义的,因为"this“是脱离上下文的。
真正起作用的是将整个localPath对象传递到操作中。
因此,在您的方法中,您可以这样做:
test(){
let route = this.localePath({ name: 'forgotPassword' })
this.$store.dispatch('storeTest', route)
},然后在动作中你可以这样做:
storeTest({ commit }, route){
this.app.router.push(route) //this works
$nuxt._router.push(route) //this works as well
},同样,如果其他选项不起作用,您可以将整个路由器传递到操作中。然后你可以这样做:router.push(route)
https://stackoverflow.com/questions/65776237
复制相似问题