Vuex Actioncontext

Posted on  by admin

Creates a new store. type: Object | Function. The root state object for the Vuex store.

  • If you pass a function that returns an object, the returned object is used as the root state.
  • This is useful when you want to reuse the state object especially for module reuse.

type: { [type: string]: Function }.

Register mutations on the store. The handler function always receives state as the first argument (will be module local state if defined in a module), and receives a second payload argument if there is one. type: { [type: string]: Function }. Register actions on the store. The handler function receives a context object that exposes the following properties:. And also receives a second payload argument if there is one.

type: { [key: string]: Function }. Register getters on the store. The getter function receives the following arguments:. Specific when defined in a module.

Are you avoiding using Vuex because there’s just too much boilerplate or because it doesn’t fully provide TypeScript support? Read on

Registered getters are exposed on store.getters. An object containing sub modules to be merged into the store, in the shape of:.

Each module can contain state and mutations similar to the root options. A module's state will be attached to the store's root state using the module's key. A module's mutations and getters will only receives the module's local state as the first argument instead of the root state, and module actions' context.state will also point to the local state.

type: Array. An array of plugin functions to be applied to the store.

The plugin simply receives the store as the only argument and can either listen to mutations (for outbound data persistence, logging, or debugging) or dispatch mutations (for inbound data e.g.

websockets or observables). Force the Vuex store into strict mode. In strict mode any mutations to Vuex state outside of mutation handlers will throw an Error.

Store #

Turn the devtools on or off for a particular Vuex instance. For instance, passing false tells the Vuex store to not subscribe to devtools plugin. Useful when you have multiple stores on a single page. The root state. Exposes registered getters.


Commit a mutation. options can have root: true that allows to commit root mutations in namespaced modules. Dispatch an action. options can have root: true that allows to dispatch root actions in namespaced modules.

Returns a Promise that resolves all triggered action handlers. Replace the store's root state. Use this only for state hydration / time-travel purposes.

Reactively watch fn's return value, and call the callback when the value changes.

fn receives the store's state as the first argument, and getters as the second argument.

Accepts an optional options object that takes the same options as Vue's vm.$watch method.

To stop watching, call the returned unwatch function. Subscribe to store mutations. The handler is called after every mutation and receives the mutation descriptor and post-mutation state as arguments.