question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can you tell me how to call a mutation from a mutation in a vuex module?

See original GitHub issue

As a example:

import {
  Module,
  VuexModule,
  Mutation,
  Action,
} from 'vuex-module-decorators'

import Vuex from 'vuex';
import Vue from 'vue'
Vue.use(Vuex);

@Module({
  name: 'Block',
  namespaced: true,
  dynamic: true,
  store: new Vuex.Store({}),
})
export default class Block extends VuexModule {

  @Mutation
  oneMutation( payload ) {

    let { var1, var2 } = payload;
    
    let var3 = this.otherMutation(var1); // <-- that!

    this.stateVariable = var3 + var2;

  }
  
  @Mutation
  otherMutation( var ) {
      // ... some calculations
  }

}

the fact is that I need methods available both from the mutation and from other components.

Thank you!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
perska124commented, Sep 12, 2019

I might be wrong but i think mutation should only change the state and not do other stuff. If you want to do few mutations at once maybe you should create an action instead?

0reactions
adminoidcommented, Sep 29, 2019

Okay, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations | Vuex
To invoke a mutation handler, you need to call store.commit with its type: ... Whether to use constants is largely a preference -...
Read more >
Can I call commit from one of mutations in Vuex store
Yes, it is possible to have a commit from another mutation with no side-effects. But debugging an incorrect state change when we have...
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 >
Call a Root Vuex Mutation or Action from within a Module in ...
You go to LoginModule, you see there we are setting the rootState to second parameter of the module type. To fix it, go...
Read more >
Vuex Tutorial #6 - Mutations - YouTube
Hey all, in this Vuex tutorial I'll show you how to mutate data on the store. Mutations allow us to track when and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found