index.js 787 B

123456789101112131415161718192021222324252627
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. // https://webpack.js.org/guides/dependency-management/#requirecontext
  5. const modulesFiles = require.context('./modules', true, /\.js$/)
  6. // you do not need `import app from './modules/app'`
  7. // it will auto require all vuex module from modules file
  8. const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  9. // set './app.js' => 'app'
  10. const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  11. const value = modulesFiles(modulePath)
  12. // console.log('----',moduleName,value);
  13. value.default.namespaced=true;
  14. modules[moduleName] = value.default
  15. return modules
  16. }, {})
  17. // this.$store.dispatch/commit/getters('baseconfig/getBaseconfig')
  18. const store = new Vuex.Store({
  19. modules
  20. })
  21. export default store