Actions | vue mutation map
![Actions](https://i.imgur.com/axBPWDg.jpg)
Actionsaresimilartomutations,thedifferencesbeingthat:Insteadofmutatingthestate,actionscommitmutations.Actionscancontainarbitraryasynchronousoperations.Letsregisterasimpleaction:Actionhandlersreceiveacontextobjectwhichexposesthesamesetofmethods/propertiesonthestoreinstance,soyoucancallcontext.committocommitamutation,oraccessthestateandgettersviacontext.stateandcontext.getters.Wecanevencallotheractionswithcontext.dispatch.WewillseewhythiscontextobjectisnotthestoreinstanceitselfwhenweintroduceM...
![Actions](http://pix4.agoda.net/hotelimages/agoda-homes/5899847/61e1a790eeb181e40e8f262ea5a396dc.jpg?s=800x)
Actions are similar to mutations, the differences being that:
Instead of mutating the state, actions commit mutations. Actions can contain arbitrary asynchronous operations.Lets register a simple action:
Action handlers receive a context object which exposes the same set of methods/properties on the store instance, so you can call context.commit to commit a mutation, or access the state and getters via context.state and context.getters. We can even call other actions with context.dispatch. We will see why this context object is not the store instance itself when we introduce Modules[1] later.
In practice, we often use ES2015 argument destructuring(opens new window)[2] to simplify the code a bit (especially when we need to call commit multiple times):
Dispatching ActionsActions are triggered with the store.dispatch method:
This may look silly at first sight: if we want to increment the count, why dont we just call store.commit(increment) directl...
取得本站獨家住宿推薦 15%OFF 訂房優惠
本站住宿推薦 20%OFF 訂房優惠,親子優惠,住宿折扣,限時回饋,平日促銷
Mutations | vue mutation map
Actions | vue mutation map
Modules | vue mutation map
State | vue mutation map
Vuex mapMutations - How does it work? | vue mutation map
How can I mutate my module store state using map mutations from a ... | vue mutation map
Vuex Map Helpers | vue mutation map
vuex-map | vue mutation map
maoberlehnervuex-map-fields: Enable two | vue mutation map
[Vue.js] Vuex 學習筆記(7) | vue mutation map
Best practices for Vuex mapping | vue mutation map
Vuejs : mapMutations | vue mutation map
vuex (2) | vue mutation map
![](https://i.imgur.com/axBPWDg.jpg)