vuex-action
Utilities for vuex to easily create and manage actions.
- Allow you to create
untyped
action - Support for
Promise
- Work with
vue@1
andvue@2
Installation
npm install --save vuex-action
API
createAction(type?: string, payloadHandler?: () => any | Promise)
It creates an action
, and the action type
will generated by uuidV4() if not specified.
createActions(prefix?: string, payloadHandlers: Array | Object)
Similarly, creates a lot of actions.
Usage
For complete examples, see examples
// Create an action const increment = // Or const increment =
With normal function:
// PayloadHandler allows you to customize the payload const add = // Therefore store // + 1 store // + 5
With Promise:
// Here is a function to fetch a user const fetchUserApi = { return Promise } // Return a Promise const fetchUser = store // payload = {username: 'Harrie'}
Or create actions together:
// use `createActions` instance of `createAction`const actions =
The store:
const store = state: count: 0 user: null mutations: // Just make it as a type { statecount += num } { stateuser = user } actions: increment fetchUser