import Vuex from 'vuex'
const store = new Vuex.Store({ ...options })
state
Object
The root state object for the Vuex store.
mutations
Object
An object where each entry's key is the mutation name and the value is a mutation handler function. The handler function always receives state
as the first argument, and receives all arguments passed to the dispatch call following that.
modules
Object
An object containing sub modules to be merged into the store, in the shape of:
{
key: {
state,
mutations
},
...
}
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 will only receives the module's own state as the first argument instead of the root state.
middlewares
Array<Object>
An array of middleware objects that are in the shape of:
{
snapshot: Boolean, // default: false
onInit: Function,
onMutation: Function
}
All fields are optional. Details
strict
Boolean
false
Force the Vuex store into strict mode. In strict mode any mutations to Vuex state outside of mutation handlers will throw an Error.
state
Object
The root state. Read only.
Directly dispatch a mutation. This is useful in certain situations are in general you should prefer using actions in application code.
Object-Style Dispatch
requires >=0.6.2
You can also dispatch mutations using objects:
store.dispatch({
type: 'INCREMENT',
payload: 10
})
Watch a path or a getter function's value, and call the callback when the value changes. Accepts an optional options object that takes the same options as Vue's vm.$watch
method.
To stop watching, call the returned handle function.
Hot swap new actions and mutations. Details