[英][Vue.js]Namespacing in vuex
我正在嘗試為模塊的getter,mutations,actions命名,我在這里看到了這個文檔 ,但是似乎有點含糊。
// 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) { // ... } } }
然后如何在vue組件中使用模塊化的吸氣劑,突變?
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']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.