[Vue.js] vuex中的命名空间

时间:2016-11-11 14:24:03

标签: javascript vue.js vuex

我正在尝试命名模块的getter,mutgest,actions,我看到这个document here,但它看起来有点模糊。

sig Person {father: Person}

fact {
    no p: Person | p in p.^father
}

assert Every_Person_Has_A_Father {
   all p: Person | some p.father
}

check Every_Person_Has_A_Father

然后我如何使用模块化的getter,vue组件中的突变?

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

1 个答案:

答案 0 :(得分:3)

this.$store.getters['todos/DONE_COUNT']