1

我正在尝试使用来自nuxt-i18n 的localRoute 方法

this.$router.push(this.localeRoute({ name: "home" }))

我试过这种方法,但它不起作用,正确的方法是什么?

4

1 回答 1

1

在 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)

于 2021-04-09T16:36:39.823 回答