Vuex Action vs Mutations

前端 未结 13 1102
囚心锁ツ
囚心锁ツ 2020-12-02 04:37

In Vuex, what is the logic of having both \"actions\" and \"mutations?\"

I understand the logic of components not being able to modify state (which seems smart), but

13条回答
  •  甜味超标
    2020-12-02 05:12

    The main differences between Actions and Mutations:

    1. In mutations you can change the state but not it actions.
    2. Inside actions you can run asynchronous code but not in mutations.
    3. Inside actions you can access getters, state, mutations (committing them), actions (dispatching them) etc in mutations you can access only the state.

提交回复
热议问题