All Projects → varHarrie → vuex-action

varHarrie / vuex-action

Licence: MIT License
🔨 Utilities for vuex to easily create and manage actions.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vuex-action

Monkov
A blog system built with vue and koa
Stars: ✭ 234 (+766.67%)
Mutual labels:  vuejs2
Vue Product Zoomer
Zoom Prodct Image, useful for e-shop website
Stars: ✭ 248 (+818.52%)
Mutual labels:  vuejs2
vue-filter-date-format
Simple date formatting filter for Vue.js
Stars: ✭ 111 (+311.11%)
Mutual labels:  vuejs2
Vue Axios Github
Vue 全家桶 + axios 前端实现登录拦截、登出、拦截器等功能
Stars: ✭ 2,622 (+9611.11%)
Mutual labels:  vuejs2
Vue Mapbox Gl
A Vue.js component for Mapbox GL JS
Stars: ✭ 242 (+796.3%)
Mutual labels:  vuejs2
H5 Editor
📕h5可视化编辑器,支持添加图片/文本/形状等,拥有图层/参考线/标尺/自动吸附对齐等功能
Stars: ✭ 224 (+729.63%)
Mutual labels:  vuejs2
Vue Element Loading
⏳ Loading inside a container or full screen for Vue.js
Stars: ✭ 234 (+766.67%)
Mutual labels:  vuejs2
vue2-codemirror-lite-js
🎩 Lightweight CodeMirror component for Vue.js 2.x (JS only with linting via JSHINT)
Stars: ✭ 16 (-40.74%)
Mutual labels:  vuejs2
Vue Examples
Collection of Vue examples for beginner front end developers
Stars: ✭ 244 (+803.7%)
Mutual labels:  vuejs2
RumahSakitJakarta
🏥 Daftar Rumah Sakit Umum, Khusus dan Puskesmas di Jakarta
Stars: ✭ 23 (-14.81%)
Mutual labels:  vuejs2
Vue Scroll
Scroll directive on vue
Stars: ✭ 238 (+781.48%)
Mutual labels:  vuejs2
Vue Tabs
Simplified bootstrap tabs
Stars: ✭ 241 (+792.59%)
Mutual labels:  vuejs2
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (+837.04%)
Mutual labels:  vuejs2
Copilot
Responsive Bootstrap 3 Admin Template based on AdminLTE with vue.js
Stars: ✭ 2,698 (+9892.59%)
Mutual labels:  vuejs2
dynamoc
A DynamoDB GUI client https://ieiayaobb.github.io/dynamoc/
Stars: ✭ 70 (+159.26%)
Mutual labels:  vuejs2
Vue Fab
Vue Floating Action Button
Stars: ✭ 233 (+762.96%)
Mutual labels:  vuejs2
Vue Cnode
🔥Vue.js打造一个开源的CNode社区。CNode by Vue.js
Stars: ✭ 249 (+822.22%)
Mutual labels:  vuejs2
vue-tutorial
A short, sweet, fast rampup tutorial for Vuejs
Stars: ✭ 27 (+0%)
Mutual labels:  vuejs2
remote-pad-gui
Desktop app to start remote pad services to help you get started
Stars: ✭ 17 (-37.04%)
Mutual labels:  vuejs2
blog-frontend
Frontend of blog created using: GraphQL (Apollo) + Vue + Nuxt.js + TypeScript + Vuetify...
Stars: ✭ 43 (+59.26%)
Mutual labels:  vuejs2

vuex-action

Utilities for vuex to easily create and manage actions.

  • Allow you to create untyped action
  • Support for Promise
  • Work with vue@1 and vue@2

Installation

  npm install --save vuex-action

API

  import {createAction, createActions} from 'vuex-action'

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 = createAction('ACTION_TYPE')
  // Or
  const increment = createAction()

With normal function:

  // PayloadHandler allows you to customize the payload
  const add = createAction((num) => num || 1)
  // Therefore
  store.dispatch('add') // + 1
  store.dispatch('add', 5) // + 5

With Promise:

  // Here is a function to fetch a user
  const fetchUserApi = function (name) {
    return Promise.resolve({username: name})
  }
  // Return a Promise
  const fetchUser = createAction((name) => fetchUserApi(name))
  store.dispatch('fetchUser', 'Harrie') // payload = {username: 'Harrie'}

Or create actions together:

// use `createActions` instance of `createAction`
const actions = createActions([
  'increment',
  {
    add: (num) => num || 1,
    fetchUser: (name) => fetchUserApi(name)
  }
])

The store:

  const store = new Vuex.Store({
    state: {
      count: 0,
      user: null
    },
    mutations: {
      // Just make it as a type
      [increment] (state, num) {
        state.count += num
      },
      [fetchUser] (state, user) {
        state.user = user
      }
    },
    actions: {
      increment,
      fetchUser
    }
  })

Inspired by

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].