Fiz*_*han 42 vue.js vuex vuejs2
我的vuex商店里有两个模块.
var store = new Vuex.Store({
modules: {
loading: loading
posts: posts
}
});
Run Code Online (Sandbox Code Playgroud)
在该模块中loading
,我有一个属性saving
,其可以被设置true
或false
也有一个名为变异函数TOGGLE_SAVING
来设置该属性.
在模块中posts
,在获取帖子之前和之后,我想要更改属性saving
.我是通过调用模块commit('TOGGLE_SAVING')
中的一个动作来完成的posts
.
var getPosts = function (context) {
contex.commit(TOGGLE_LOADING);
};
Run Code Online (Sandbox Code Playgroud)
当它尝试提交时,我在控制台中出现以下错误
[vuex] unknown local mutation type: TOGGLE_LOADING, global type: posts/TOGGLE_LOADING
Run Code Online (Sandbox Code Playgroud)
如何在另一个模块中使用变异状态commit
?
Sau*_*abh 77
按照此处的建议使用以下参数进行尝试;
commit('TOGGLE_LOADING', null, { root: true })
Run Code Online (Sandbox Code Playgroud)
如果你namespaced
设置为true(在Nuxt中,这是模块模式下的默认值),这将变为:
commit('loading/TOGGLE_LOADING', null, { root: true })
Run Code Online (Sandbox Code Playgroud)