我有一个相当大的VueJS SPA,我只是想使用懒惰的负载在某些路由上加载Vuex模块。
我是为了复制这篇文章-
https://alexjoverm.github.io/2017/07/16/Lazy-load-in-Vue-using-Webpack-s-code-splitting/
但是这给了我一个Vuex错误。
文件夹结构
root
|- store
| |- modules
| | |- auth.js
| | |- module2.js
| |- store.js
|- app.js
认证JS
const state = {
var1: {},
var2: false
}
const mutations = {
'MUTATION_1'(state, obj) {
// logic
}
}
const actions = {
action1({commit}) {
// logic
}
}
const getters = {
var1: state => state.var1,
var2: state => state.var2
}
export default {
state,
mutations,
actions,
getters
}
商店.js-
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const store = new Vuex.Store();
import('./modules/auth.js').then(auth => {
store.registerModule('/login', auth);
});
export default store;
应用程序JS-
import Vue from 'vue';
import store from './store/store';
import VueRouter from 'vue-router';
import { routes } from './routes/routes';
// vue-router config
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes
});
const app = new Vue({
el: '#app',
store,
router
});
错误-
[vuex] unknown getter: var1
有什么建议吗?