2016-11-11 2 views
2

Я пытаюсь использовать имена модулей, получателей, мутаций, действий, я вижу это document here, но это кажется немного расплывчатым.[Vue.js] Namespacing в vuex

// 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) { 
 
     // ... 
 
    } 
 
    } 
 
}

И тогда, как я использую moduled добытчиками, мутации в 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: ?, 
 
    }, 
 
};

+1

решить эту проблему с помощью mapGetters в '' vuex – Kim

ответ

Смежные вопросы