Correct way to call a mutation within an action
See original GitHub issueHey everyone,
I have a short question, if this is a correct way to trigger a mutation within an action:
export class MyModule extends VuexModule {
myProp: string = '';
@Mutation
private SET_MY_PROP(value: string) {
this.myProp = value;
}
@Action
public async setMyProp(value: string) {
this.SET_MY_PROP(value);
}
}
I am asking, because those get started examples commit the mutation differently like:
@Action({ commit: 'SET_MY_PROP' })
async setMyProp(value: string) {
return value;
}
or like
@Action
async setMyProp(value: string) {
this.context.commit('SET_MY_PROP', value);
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:5
Top Results From Across the Web
Vuex showdown: Mutations vs. actions - LogRocket Blog
Actions are similar to mutations, the differences being that: Instead of mutating the state, actions commit mutations; Actions can contain ...
Read more >Please add an ability to call mutation from another ... - GitHub
If you call a mutations in other mutations, they cannot be separated in devtools and it decrease trackability.
Read more >Mutations | Vuex
The only way to actually change state in a Vuex store is by committing a mutation. Vuex mutations are very similar to events:...
Read more >Call a Root Vuex Mutation or Action from within a Module in ...
The way we can trigger a real mutation from a module is by using an action. If we go to the todos module,...
Read more >What are mutations in Vuex? - Educative.io
In the below code, we can see the state and mutation object in the store. The changeStatus mutation is used to update the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@souphuhn Personally I use the first example, calling the method instead of annotating. Reasons:
SET_MY_PROP
is actually used (and therefore not dead code)One ‘danger’ I have noticed, is that it’s tempting to use more than one argument for the mutation – your IDE won’t mind, but it won’t work as expected.
@bdockbockd just call your mutations from your actions like normal method calls