Vuex 允许我们将 store 分割成模块(module)。每个模块拥有自己的 state、mutation、action、getter、甚至是嵌套子模块——从上至下进行同样方式的分割:

    1. const moduleA = {
    2. state: () => ({ ... }),
    3. mutations: { ... },
    4. actions: { ... },
    5. getters: { ... }
    6. }
    7. const moduleB = {
    8. state: () => ({ ... }),
    9. mutations: { ... },
    10. actions: { ... }
    11. }
    12. const store = new Vuex.Store({
    13. modules: {
    14. a: moduleA,
    15. b: moduleB
    16. }
    17. })
    18. store.state.a // -> moduleA 的状态
    19. store.state.b // -> moduleB 的状态