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')
}
}
魑魅魍魉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')
}
}
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