[Vuejs]-Vuex / Vue-Router – Passing auth:user id from vuex store to vue-router router-link params

1πŸ‘

βœ…

The problem seems to be in accessing store because by default, this.$store is injected to components so you can just use $store in templates, which then should be:

<router-link :to="{ name: 'employee-objective', params: { id: $store.state.authUser }}">

However, in accessing store state values, the recommended way is to use vuex’s mapState Helper.

computed: {
  ...mapState([
    // map this.authUser to store.state.authUser 
    'authUser '
  ])
}

and so you can use this as so:

<router-link :to="{ name: 'employee-objective', params: { id: authUser }}">

Leave a comment