0 votes
in VueJS by
Give an example usage of actions?

1 Answer

0 votes
by

Vuex provides actions property similar mutations property in order to define action handlers. These action handlers receive context object as an argument which has same properties and methods of store instance.

Let's see counter example to demonstrate increment action which commits respective mutation,

const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    increment (state) {
      state.count++
    }
  },
  actions: {
    increment (context) {
      context.commit('increment')
    }
  }
})

Related questions

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