store.js 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import * as actions from './actions'
  4. import * as getters from './getters'
  5. Vue.use(Vuex)
  6. // 应用初始状态
  7. // const state = {
  8. // count: 10
  9. // }
  10. // // 定义所需的 mutations
  11. // const mutations = {
  12. // INCREMENT(state) {
  13. // state.count++
  14. // },
  15. // DECREMENT(state) {
  16. // state.count--
  17. // },
  18. // getRole(res) {
  19. // console.log(res)
  20. // }
  21. // }
  22. // // 创建 store 实例
  23. // export default new Vuex.Store({
  24. // actions,
  25. // getters,
  26. // state,
  27. // mutations
  28. // })
  29. const store = new Vuex.Store({
  30. state: {
  31. user: ''
  32. },
  33. getters: {
  34. getName(state) {
  35. return 'hello ' + state.name;
  36. }
  37. },
  38. mutations: {
  39. mutationSetName(state, name) {
  40. state.name = name;
  41. }
  42. },
  43. actions: {
  44. getRole(context, res) {
  45. }
  46. }
  47. });
  48. export default store;