0 votes
in VueJS by

What is vuex plugin?

1 Answer

0 votes
by

The vuex plugin is an option hat exposes hooks for each mutation. It is a normal function that receives the store as the only argument. You can create your own plugin or use built-in plugins. The plugin skeleton would be as below,

const myPlugin = store => {
  // called when the store is initialized
  store.subscribe((mutation, state) => {
    // called after every mutation.
    // The mutation comes in the format of `{ type, payload }`.
  })
}

After that plugin can be configured for plugins options as below,

const store = new Vuex.Store({
  // ...
  plugins: [myPlugin]
})

Related questions

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