|
@@ -3,56 +3,22 @@ import Vuex from '../../src'
|
|
|
|
|
|
Vue.use(Vuex)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-const INCREMENT = 'INCREMENT'
|
|
|
-const DECREMENT = 'DECREMENT'
|
|
|
-
|
|
|
|
|
|
|
|
|
const state = {
|
|
|
count: 0
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-const actions = {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- increment: INCREMENT,
|
|
|
- decrement: DECREMENT,
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- incrementIfOdd: ({ dispatch, state }) => {
|
|
|
- if ((state.count + 1) % 2 === 0) {
|
|
|
- dispatch(INCREMENT)
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- incrementAsync: ({ dispatch }) => {
|
|
|
- setTimeout(() => {
|
|
|
- dispatch(INCREMENT)
|
|
|
- }, 1000)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
- [INCREMENT] (state) {
|
|
|
+ INCREMENT (state) {
|
|
|
state.count++
|
|
|
},
|
|
|
- [DECREMENT] (state) {
|
|
|
+ DECREMENT (state) {
|
|
|
state.count--
|
|
|
}
|
|
|
}
|
|
@@ -61,12 +27,11 @@ const mutations = {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
|
|
state,
|
|
|
- actions,
|
|
|
mutations
|
|
|
})
|