Skip to content

Instantly share code, notes, and snippets.

@EmilyRosina
Last active August 8, 2018 15:45
Show Gist options
  • Save EmilyRosina/77b46da6feeeb81a83cd8c5a6f03daaa to your computer and use it in GitHub Desktop.
Save EmilyRosina/77b46da6feeeb81a83cd8c5a6f03daaa to your computer and use it in GitHub Desktop.

in modules/index.js

  import camelCase from 'lodash/camelCase'
  const requireModule = require.context('.', false, /\.js$/)
  const modules = {}
  
  requireModule.keys().forEach(fileName => {
    // Don't register index.js
    if (fileName === './index.js') return
    
    const moduleName = camelCase(fileName.replace(/(\.\/|\.js)/g, ''))
    modules[moduleName] = {
      namespaced: true,
      ...requireModule(fileName)
    }
  })
  
  export default modules

in store/index.js

  import Vue from 'vue'
  import Vuex from 'vuex'
  import getters from './getters'
  import state from './state'
  import actions from './actions'
  import mutations from './mutations'
  import modules from './modules'
  
  Vue.use(Vuex)
  
  export default new Vuex.Store({
    modules,
    state,
    getters,
    actions,
    mutations
  })

in src/index.js

  ...
  import Store from './store'
  ...
  new Vue({
    Store,
    Router,
    el: '#app'
  })
  

source: https://www.youtube.com/watch?v=7YZ5DwlLSt8&t=614s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment