Action 類似于 mutation,不同在于:
Action 提交的是 mutation,而不是直接變更狀態(tài)。
Action 可以包含任意異步操作。
注冊一個簡單的 action:

Action 函數(shù)接受一個與 store 實例具有相同方法和屬性的 context 對象,因此可以調(diào)用?context.commit?提交一個 mutation,或者通過?context.state?和?context.getters?來獲取 state 和 getters。

分發(fā) Action
Action 通過?store.dispatch?方法觸發(fā):

mutation 必須同步執(zhí)行,Action 就不受約束,?在 action 內(nèi)部執(zhí)行異步操作:
在addAction里使用setTimeOut進行延遲執(zhí)行

Actions 支持同樣的載荷方式和對象方式進行分發(fā):

接收載荷:

mapActions輔助函數(shù)
在組件中使用?this.$store.dispatch('xxx')?分發(fā) action,或者使用?mapActions輔助函數(shù)將組件的 methods 映射為?store.dispatch?調(diào)用(需要先在根節(jié)點注入?store):

組合 Action
待續(xù)。。。。