0
votes

I am trying tp pass an id param when the user click on the link generated by but I don't see it in the html The id should be the currentUserId set or initialised in store .. so I defined a computed prop and appropriate getter ('getCurrentUserId') which pick up the currentUserId from the state.. Where am I wrong ?

<li id="shoppinglists"><a href="#/shoppinglists" class="">Shopping Lists</a></li>

I should get :

href="#/shoppinglists/1"

App.vue

<template>
  <div id="app">
    <ul class="navigation">
      <li id="home"><router-link :to="{ name: 'Home' }" >Home</router-link></li>
      <li id="shoppinglists"><router-link :to="{ name: 'ShoppingLists', params: { id: currentUserId } }" >Shopping Lists</router-link></li>
    </ul>
    <router-view></router-view>
  </div>
</template>

<script>
import store from '@/vuex/store'
import { mapGetters } from 'vuex'

export default {
  name: 'app',
  computed: {
    ...mapGetters({ currentUserId: 'getCurrentUserId' })
  },
  store
}
</script>

vuex/getters.js

import _ from 'underscore'

export default {
  getCurrentUserId: state => state.currentUserId,
  ...
}

vuex/store.js

import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import actions from './actions'
import mutations from './mutations'

Vue.use(Vuex)

const state = {
  currentUserId: 1,
  ...
}

export default new Vuex.Store({
  state,
  mutations,
  getters,
  actions
})
1

1 Answers

0
votes

Ok got it .. it's not concatenated with the ref url... but using vue web-tools I can see that' the object to: has both the path '/shoppinglists' and params: object {id: 1}... it's not obvious to switch mindset to vue behaviour ...