mapActions(namespace?: string, map: Array | Object): ObjectĬreate component methods options that dispatch an action.The first argument can optionally be a namespace string. mapGetters(namespace?: string, map: Array | Object): ObjectĬreate component computed options that return the evaluated value of a getter.mapState(namespace?: string, map: Array | Object): ObjectĬreate component computed options that return the sub tree of the Vuex store.
Details # Component Binding Helpers # mapState Details # hasModuleĬheck if the module with the given name is already registered. Options can have preserveState: true that allows to preserve the previous state. registerModule(path: string | Array, module: Module, options?: Object).The subscribeAction method is most commonly used in plugins. The handler is called after every mutation and receives the mutation descriptor and post-mutation state as arguments. subscribe(handler: Function, options?: Object): Function.To stop watching, call the returned unwatch function. Accepts an optional options object that takes the same options as Vue's vm.$watch method (opens new window).
fn receives the store's state as the first argument, and getters as the second argument. Reactively watch fn's return value, and call the callback when the value changes. watch(fn: Function, callback: Function, options?: Object): Function.Use this only for state hydration / time-travel purposes. Returns a Promise that resolves all triggered action handlers. options can have root: true that allows to dispatch root actions in namespaced modules. dispatch(action: Object, options?: Object): Promiseĭispatch an action.dispatch(type: string, payload?: any, options?: Object): Promise.options can have root: true that allows to commit root mutations in namespaced modules. commit(mutation: Object, options?: Object)Ĭommit a mutation.commit(type: string, payload?: any, options?: Object).Useful for if you have multiple stores on a single page. For instance passing false tells the Vuex store to not subscribe to devtools plugin. Turn the devtools on or off for a particular vuex instance. In strict mode any mutations to Vuex state outside of mutation handlers will throw an Error. websockets or observables).įorce the Vuex store into strict mode. 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. 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.Īn array of plugin functions to be applied to the store. A module's state will be attached to the store's root state using the module's key. Each module can contain state and mutations similar to the root options.