首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在vuex中使用nuxt-i18n包中的localeRoute

如何在vuex中使用nuxt-i18n包中的localeRoute
EN

Stack Overflow用户
提问于 2021-01-18 22:17:15
回答 1查看 212关注 0票数 1

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2021-04-10 00:36:40

在vuex中,this.localRoute或this.localPath是未定义的,因为"this“是脱离上下文的。

真正起作用的是将整个localPath对象传递到操作中。

因此,在您的方法中,您可以这样做:

代码语言:javascript
复制
test(){
      let route = this.localePath({ name: 'forgotPassword' })
      this.$store.dispatch('storeTest', route)
    },

然后在动作中你可以这样做:

代码语言:javascript
复制
  storeTest({ commit }, route){

     this.app.router.push(route) //this works
     $nuxt._router.push(route) //this works as well
  },

同样,如果其他选项不起作用,您可以将整个路由器传递到操作中。然后你可以这样做:router.push(route)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65776237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档