import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'
import getters from './getters'

Vue.use(Vuex)

let store

const initStore = () => {
  return store || (store = new Vuex.Store({
    // 存放公用数据
    state,
    // 异步操作要通过actions，否则通过cimmit直接操作mutations
    actions,
    // 同步放数据
    mutations,
    getters,
    modules: {
      // store 模块....
    }
  }))
}

export default initStore

