programing

vuex에서 nuxt-i18n 패키지의 localRoute를 사용하는 방법

prostudy 2022. 8. 3. 21:02
반응형

vuex에서 nuxt-i18n 패키지의 localRoute를 사용하는 방법

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)

언급URL : https://stackoverflow.com/questions/65776237/how-to-use-localeroute-from-nuxt-i18n-package-in-vuex

반응형