-
Notifications
You must be signed in to change notification settings - Fork 1
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
有自己的 namespace
、state
和 actions
:
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's state
modules._rootState.moduleb.state // -> moduleB's state
It should be noted that the namespace
of each module
must be unique and must be named in lowercase.
需要注意的是, 每个 module
的 namespace
必须是唯一的且必须以小写字母命名.