getters补充
当getters写在子模块的时候,getters属性中的方法,全参共有4个参数
参数说明:
- state: 表示当前模块中的state
- getters: 表示当前模块中的getters对象
- rootState: 表示主模块的state对象
- rootGetters: 表示主模块的getters对象
说明:主模块即index.js中的
// 示例
getNumber (state, getters, rooteState, rootGetters) {
// state、getters直接调用即可
// rootState.模块名.属性名
// rootGetters['模块名/该模块下的getters方法名']
}
actions补充
当actions在子模块的时候
getRouters (context, value) {
// context是一个对象,如果当前actions定义在子模块中,context对象中会有以下6个提供给开发者使用的对象
1.commit: 调用mutations
1> 本模块调用: commit('本模块mmutations方法名', 实参)
2>其他模块调用:commit('模块名/其他模块的mutations', 实参, {root: true})
// root: true是固定参数,表示作为主模块去调用的意思
2.state: 获取当前模块的state
3.dispatch: 调用actions方法
1>本模块调用: dispatch('本模块的actions方法名',实参)
2>其他模块的调用: dispatch('模块名/其他模块的actions方法名', null, {root: true})
4.getters: 获取当前模块的getters
5.rootState:主模块下的state
6.rootGetters: 主模块下的getters
// 参数二 value:调用时传递的参数
getInfo (context, value) {}
// 其中context的解构赋值写法为:
getInfo ({commit, rootGetters}, value) {}
}
-