123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import Vue from 'vue'
- 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) {
- state.count++
- },
- [DECREMENT] (state) {
- state.count--
- }
- }
- export default new Vuex.Store({
- state,
- actions,
- mutations
- })
|