Created
August 13, 2020 06:28
-
-
Save Javison666/d53b056422cbffd918697c8c9db6b062 to your computer and use it in GitHub Desktop.
vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import Vuex from 'vuex' | |
// import persistedState from 'vuex-persistedstate' | |
import getters from './getters' | |
// import { DOMAINID } from '@/config' | |
// eslint-disable-next-line no-unused-vars | |
// import app from './modules/app' | |
// eslint-disable-next-line no-unused-vars | |
// import settings from './modules/settings' | |
Vue.use(Vuex) | |
// https://webpack.js.org/guides/dependency-management/#requirecontext | |
const modulesFiles = require.context('./modules', true, /\.js$/) | |
// you do not need `import app from './modules/app'` | |
// it will auto require all vuex module from modules file | |
const modules = modulesFiles.keys().reduce((modules, modulePath) => { | |
// set './app.js' => 'app' | |
const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1') | |
const value = modulesFiles(modulePath) | |
modules[moduleName] = value.default | |
return modules | |
}, {}) | |
const store = new Vuex.Store({ | |
modules, | |
getters | |
// plugins: [persistedState({ | |
// key: `${DOMAINID}-vuex`, | |
// reducer: state => ({ | |
// user: state.user, | |
// settings: state.settings | |
// }) | |
// })] | |
}) | |
export default store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment