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.

MutationAction not having access to module state?

See original GitHub issue

Is this by design or am I doing something wrong ?

The snippet bellow breaks because this.value is undefined.

When using this.state.value it works but the type is all wrong, so I get a lot of TS error.

Am I missing something?

@Module
class Mod extends VuexModule {
   public value = 2;

   @MutationAction({ mutate: ["value"] })
   async valueIncrement(): Promise<Record<"value", number>> {
      const req: AxiosRequest = await axios.get("...randomValue/");

      return {
         value: this.value += req.data
      }
   }
}

If possible, someone please send me a link to a Discord community with people who know Vuex Module Decorators.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
NikhilVermacommented, Aug 11, 2021

I made a PR which documents how to “fix” this issue - https://github.com/championswimmer/vuex-module-decorators/pull/374

0reactions
ymarcovcommented, Sep 25, 2021

Since the repo has not been updated in over a year, I have forked it and applied the update mention above, so that state and getters can be accessed from a MutationAction similarly to Action.

To use my fork you can replace the vuex-module-decorators dependency line in your package.json file as follows:

"vuex-module-decorators": "github:ymarcov/vuex-module-decorators"

then run npm update vuex-module-decorators

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue - how to access the state within MutationAction
I can't access the state inside @MutationAction. I'm using: Nuxt.js v2.13.3 "vuex-module-decorators": "^0.17.0" import { Module, VuexModule ...
Read more >
【Vue】vuex-module-decorators详细使用手册 - 51CTO博客
import { VuexModule, Module, Mutation, Action } from ... If state value cannot be determined, it MUST be initialized with ​ ​null​ ​​....
Read more >
Overview | vuex-module-decorators - championswimmer
With this library, you can write vuex modules in this format -. // eg. /app/store/posts.ts import { VuexModule, Module, Mutation, Action } from ......
Read more >
How To Manage State in a Vue.js Application with Vuex
Getters are methods that can modify or combine data to create a new state property. These getters are read-only and do not mutate...
Read more >
Vuex showdown: Mutations vs. actions - LogRocket Blog
They not only allow you to change your state, but also serve an organizational and ... Why can't mutations have access to getters?...
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