Vuex

 Vuex

改变 store 中的状态的唯一途径就是显式地提交 (commit) mutation。在 Vuex 中,mutation 都是同步事务。

 

Action 类似于 mutation,不同在于:

  • Action 提交的是 mutation,而不是直接变更状态。
  • Action 可以包含任意异步操作。
getters: {
  isAdmin () { ... } // -> getters['isAdmin']
},
actions: {
  login () { ... } // -> dispatch('login')
},
mutations: {
  login () { ... } // -> commit('login')
}

 

posted @ 2018-10-19 17:39  霓裳依旧  阅读(129)  评论(0编辑  收藏  举报