Reputation: 5729
Store file:
state: {
...
cases: [],
...
mutations: {
setCases(state, items) {
// items contains only the first object in the array
...
Component:
// resp is an array received from axios.get:
this.$store.commit({
type: 'setCases',
items: resp
})
resp is an object array. When Vuex calls the setCases() mutation, only the first object of the array is delivered in 'items'.
Why is that?
Upvotes: 3
Views: 1478
Reputation: 466
Looking at this: https://vuex.vuejs.org/guide/mutations.html [see Object-Style Commit section]
When using object-style commit, the entire object will be passed as the payload to mutation handlers, so the handler remains the same
The resp
value should be accessible as items.items
in the mutation function.
Upvotes: 2