search

Home  >  Q&A  >  body text

javascript - vuex parameter destructuring problem

When I was using vuex, I saw parameter destructuring used, but I was wondering, where did this commit come from? Where is the commit parameter provided? How is it written without simplification?

actions: {
  increment ({ commit }) {
    commit('increment')
  }
}
给我你的怀抱给我你的怀抱2712 days ago853

reply all(3)I'll reply

  • 魑魅魍魉

    魑魅魍魉2017-10-16 19:52:42

      actions: {

        increment (context) {

          context.commit('increment'),

        },

        ddd(context) {

          context.commit('ddd'),

        }

      }

    用参数解构之后:

    actions: {

      increment ({ commit }) {

        commit('increment')

      },

      ddd({ commit }) {

        commit('ddd')

      }

    }


    reply
    0
  • 代言

    代言2017-06-26 10:55:45

    actions: {
    
      increment ( object ) {
    
           object.commit('increment')
      }
    
    }

    reply
    0
  • PHP中文网

    PHP中文网2017-06-26 10:55:45

    The

    Action function accepts a context object with the same methods and properties as the store instance, so you can call context.commit
    to submit a mutation, or get state and
    getters via context.state and context.getters. When we introduce Modules later, you will know why the context object is not the store instance itself.

    vuex documentation

    reply
    0
  • Cancelreply