MutationAction not having access to module state?
See original GitHub issueIs 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:
- Created 2 years ago
- Reactions:2
- Comments:5
Top 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 >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
I made a PR which documents how to “fix” this issue - https://github.com/championswimmer/vuex-module-decorators/pull/374
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 toAction
.To use my fork you can replace the
vuex-module-decorators
dependency line in yourpackage.json
file as follows:then run
npm update vuex-module-decorators