index.js 718 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * 用于代替components库对vuex的依赖
  3. */
  4. import { reactive, readonly } from 'vue'
  5. import * as defaultActions from './actions'
  6. const storeActions = defaultActions
  7. // 注册actions
  8. const registerActions = (actions) => {
  9. Object.keys(actions).forEach(key => {
  10. const action = actions[key]
  11. // 当前开放对默认action的修改
  12. storeActions[key] = action
  13. })
  14. }
  15. const state = reactive({
  16. accountInfo: {},
  17. app: {}
  18. })
  19. const dispatch = (type, payload) => {
  20. const action = storeActions[type]
  21. if (action) {
  22. action.bind(this, { state, dispatch })(payload)
  23. } else {
  24. Error('type action not found!!')
  25. }
  26. }
  27. export default {
  28. state: readonly(state),
  29. dispatch,
  30. registerActions
  31. }