如何访问 Vuex 模块的 getter 和 mutations? [英] How to access Vuex module getters and mutations?

查看:34
本文介绍了如何访问 Vuex 模块的 getter 和 mutations?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试改用 Vuex 而不是我自己开发的 store 对象,我必须说我没有找到像 Vue.js 世界中的其他地方那样清晰的文档.假设我有一个名为products"的 Vuex 模块,它有自己的状态、突变、getter 等.我如何引用该模块中名为clearWorking Data"的操作?文档给出了访问模块状态的示例:

I'm trying to switch to using Vuex instead of my homegrown store object, and I must say I'm not finding the docs as clear as elsewhere in the Vue.js world. Let's say I have a Vuex module called 'products', with its own state, mutations, getters, etc. How do I reference an action in that module called, say, 'clearWorking Data'? The docs give this example of accessing a module's state:

store.state.a // -> moduleA's state

但我看不到有关 getter、mutation、action 等的任何信息.

But nothing I can see about getters, mutations, actions, etc.

推荐答案

在您的示例中,它将是 store.dispatch('products/clearWorkingData') 您可以将操作/突变视为一个文件系统在某种程度上.模块嵌套得越深,它们在树中的位置就越深.

In your example it would be store.dispatch('products/clearWorkingData') you can think of actions/mutations as a file system in a way. The deeper the modules are nested the deeper in the tree they are.

所以如果你有一棵三层深的树,你可以去store.commit('first/second/third/method').

so you could go store.commit('first/second/third/method') if you had a tree that was three levels deep.

这篇关于如何访问 Vuex 模块的 getter 和 mutations?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆