Skip to content

Modules

Pomy edited this page Aug 24, 2017 · 7 revisions

The modules concept is from vuex-modules. To avoid modules is too bloated, we can divide modules into a single module, each module has its own namespace, state and actions:

Modules 的概念来自 vuex-modules. 为避免 modules 过于臃肿, 我们可以将 modules 分割成单一的模块(module), 每个 module 有自己的 namespacestateactions:

const moduleA = {
    // must be unique and named with lower-case
    namespace: 'modulea',
    state: {
        // module state
    },
    actions: {
        // module actions
    }
}

const moduleB = {
    // must be unique
    namespace: 'moduleb',
    state: {
        // module state
    },
    actions: {
        // module actions
    }
}

const moduleC = {
    // must be unique
    namespace: 'moduleb',
    state: {
        // module state
    },
    actions: {
        // module actions
    }
}

const modules = new Modules({
  moduleA,
  moduleB,
  moduleC
});

modules._rootState.modulea.state // -> moduleA 的状态
modules._rootState.moduleb.state // -> moduleB 的状态

It should be noted that the namespace of each module must be unique and must be named in lowercase.

需要注意的是, 每个 modulenamespace 必须是唯一的且必须以小写字母命名.

Clone this wiki locally