Assume you have a simple app component with a button to add multiple counters from a counter component using a vuex store.
Here is the whole thing on webpackbin.
A bit like the basic counter example from the vuex git repo.But you want to use the vuex getter with an ID that is handed over via a property on the component, how would you do that?
The getter has to be a pure function, so you can't use this.counterId
. The official docs say you have to use a computed property, but that doesn't seem to work either. This code returns undefined for the getter:
import * as actions from './actions'
export default {
props: ['counterId'],
vuex: {
getters: {
count: state => state.counters[getId]
},
actions: actions
},
computed: {
getId() { return this.counterId }
},
}
this
in the getter by definition. – Chris