Vuex Action vs Mutations

前端 未结 13 1105
囚心锁ツ
囚心锁ツ 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:16

    Mutations:

    Can update the state. (Having the Authorization to change the state).
    

    Actions:

    Actions are used to tell "which mutation should be triggered"
    

    In Redux Way

    Mutations are Reducers
    Actions are Actions
    

    Why Both ??

    When the application growing , coding and lines will be increasing , That time you have to handle the logic in Actions not in the mutations because mutations are the only authority to change the state, it should be clean as possible.

提交回复
热议问题