0 votes
in VueJS by
How do you commit with payload?

1 Answer

0 votes
by

You can also pass payload for the mutation as an additional argument to store.commit.

For example, the counter mutation with payload object would be as below,

mutations: {
  increment (state, payload) {
    state.count += payload.increment
  }
}

And then you can trigger increment commit

store.commit('increment', {
  increment: 20
})

Note: You can also pass primitives as payload.

Related questions

0 votes
asked Sep 12, 2023 in VueJS by GeorgeBell
0 votes
asked Sep 9, 2023 in VueJS by DavidAnderson
...