[Vue.js] vuex中的命名空间
[Vue.js]Namespacing in vuex
我试图命名空间模块的getter,突变,动作,我在这里看到这个文档,但它似乎有点模糊。
// types.js
// define names of getters, actions and mutations as constants
// and they are prefixed by the module name `todos`
export const DONE_COUNT = 'todos/DONE_COUNT'
export const FETCH_ALL = 'todos/FETCH_ALL'
export const TOGGLE_DONE = 'todos/TOGGLE_DONE'
// modules/todos.js
import * as types from '../types'
// define getters, actions and mutations using prefixed names
const todosModule = {
state: { todos: [] },
getters: {
[types.DONE_COUNT] (state) {
// ...
}
},
actions: {
[types.FETCH_ALL] (context, payload) {
// ...
}
},
mutations: {
[types.TOGGLE_DONE] (state, payload) {
// ...
}
}
}
然后我如何使用模块getter,值组件的突变?
export default {
data() {
// like this?
count: this.$store.getters.DONE_COUNT,
// ?
count: this.$store.getters.todos.DONE_COUNT,
// ?
count: this.$store.getters.todosModule.DONE_COUNT,
// ?
count: ?,
},
};
this.$store.getters['todos/DONE_COUNT']
相关文章:
- 在javascript中使用命名空间
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- javascript中的命名空间,IDE中支持代码完成/内容辅助's
- 如何使用javascript命名空间
- js命名空间和变量范围
- html,js-如何限制元素"范围“-命名空间
- 转换自的JavaScript命名空间
- 命名空间与自调用函数
- 什么's当前命名空间/类中JavaScript子命名空间/类的语法
- 无法加载Ace.js编辑器模式和主题(命名空间项目&AMD require.js&grunt
- jQuery命名空间和使用“;这个“;
- 在Firebug控制台中监视javascript命名空间变量
- jQuery事件命名空间是否可以包含破折号
- 用自定义javascript全局命名空间替换窗口
- 如何在Typescript中导出具有其他名称的命名空间
- 从html文件中的脚本标记调用非全局命名空间函数
- 正在测量全局命名空间的污染
- 谷歌闭包命名空间冲突
- socket.io:断开连接事件 - “传输关闭”、“客户端命名空间断开连接”、“传输错误”和“强制关闭”
- [Vue.js] vuex中的命名空间