4
代码修改处
src/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import createPersistedState from 'vuex-persistedstate'
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: [createPersistedState({ storage: window.sessionStorage })]
})
export default store
页面效果与报错
刚改完代码,前几次打开的页面可能还是正常的,但是重启项目或者多尝试打开几个页面,控制台就会报出以下的错误,而且页面空白:
还请作者和各位大佬,帮忙指出错误和提供意见,在此感谢了~~