如何解决如何在 vuex 中使用来自 nuxt-i18n 包的 localeRoute
我正在尝试使用来自 nuxt-i18n
的 localRoute 方法this.$router.push(this.localeRoute({ name: "home" }))
解决方法
在 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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。