vuex-promise
v2.0.0-rc.3
Published
:two_hearts: A Promise Plugin for Vuex
Downloads
182
Readme
VUEX-PROMISE
:two_hearts: A Promise Plugin for Vuex, compatible with 2.0.0-rc
Change Log
- 20160807 :warning: Breaking Changes
- modify meta structure
Usage
set plugin in store
import createPromise from 'vuex-promise'
export default new Vuex.Store({
strict: __DEV__,
...,
plugins: [createPromise({
debug: __DEV__,
status: {
PENDING: 'PROMISE_PENDING',
SUCCESS: 'PROMISE_SUCCESS',
FAILURE: 'PROMISE_FAILURE',
FINALLY: 'PROMISE_FINALLY'
},
silent: false
})]
})
define module with getters and actions
import request from 'plato-request'
import {
GET_COMMITS
} from '../types'
import {
PROMISE_SUCCESS
} from '../constants'
const state = {
commits: null
}
const getters = {
commits: state => state.commits
}
const actions = {
getCommits ({ commit }, payload) {
commit(GET_COMMITS, request('{base}/commits?sha=', {
params: {
base: 'https://api.github.com/repos/crossjs/plato'
},
query: {
per_page: 3
},
headers: {
'Accept': 'application/vnd.github.v3+json'
}
}))
}
}
const mutations = {
[GET_COMMITS] (state, { payload, meta }) {
if (meta && meta.promise === PROMISE_SUCCESS) {
state.commits = payload
}
}
}
export default {
state,
getters,
actions,
mutations
}