store.js 875 B

123456789101112131415161718192021222324252627282930313233
  1. import Vue from 'vue'
  2. import Vuex from '../../src'
  3. Vue.use(Vuex)
  4. // root state object.
  5. // each Vuex instance is just a single state tree.
  6. const state = {
  7. count: 0
  8. }
  9. // mutations are operations that actually mutates the state.
  10. // each mutation handler gets the entire state tree as the
  11. // first argument, followed by additional payload arguments.
  12. // mutations must be synchronous and can be recorded by plugins
  13. // for debugging purposes.
  14. const mutations = {
  15. INCREMENT (state) {
  16. state.count++
  17. },
  18. DECREMENT (state) {
  19. state.count--
  20. }
  21. }
  22. // A Vuex instance is created by combining the state, the actions,
  23. // and the mutations. Because the actions and mutations are just
  24. // functions that do not depend on the instance itself, they can
  25. // be easily tested or even hot-reloaded (see counter-hot example).
  26. export default new Vuex.Store({
  27. state,
  28. mutations
  29. })