Reputation: 309
i have create module in vuex, but how to access getters in computed ? here is product template
<template>
<ul>
<li v-for="item in productAll" :key="item._id">
<p>hello word</p>
</li>
</ul>
</template>
<script>
export default {
computed:{
productAll(){
return this.$store.getters.productAll
}
},
}
</script>
and this is my store
const productModule = {
state: () => ({
product: [
]
}),
getters:{
productAll(context){
return [
"123","456"
]
// return state.product.data
}
},
}
export const store = new Vuex.Store({
modules: {
productModule
},
}
i only return array 123 345 in "store.getters.productAll", if i put array 123 345 in computed it is working, will show hello word 2 times, but why when i put in store module it is not working ?
Upvotes: 0
Views: 427
Reputation: 63119
Unlike actions, getters don't receive a context
object. They receive 4 arguments:
(state, getters, rootState, rootGetters)
state
: Current module stategetters
: Current module gettersrootState
: Root module state (and module-to-module access)rootGetters
: Root module getters (and module-to-module access)So create your getter this way:
getters: {
productAll(state) {
return state.product.data
}
}
Upvotes: 1