图中为chat模块的vuex:
如上图所示,通过vuex提供的commit和dispatch方法可以调用本
模块的内容,比如:
dispatch('aaa', { *** });
commit('bbb', ***);
// 下面这样是不行的,调用不到其他模块的
dispatch('otherModule/otherModuleMethods');
// 像下方这样使用就可以了
this.dispatch('otherModule/otherModuleMethods');
// 同理下方也可以
dispatch('chatTray/initTraySessionList', {}, { root: true });
方法一:下方使用的是根模块的dispatch方法,所以可以这么玩
this.dispatch('otherModule/otherModuleMethods');
方法二: 下方是传入参数声明了从根节点搞
dispatch('chatTray/initTraySessionList', {}, { root: true });