store.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 middlewares
  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. //
  27. // You can also provide middlewares, which is just an array of
  28. // objects containing some hooks to be called at initialization
  29. // and after each mutation.
  30. export default new Vuex.Store({
  31. state,
  32. mutations
  33. })