I'm having trouble accessing the state inside @MutationAction
Here is the setup I am using:
Nuxt.js v2.13.3
"vuex-module-decorators": "^0.17.0"
import { Module, VuexModule, MutationAction } from 'vuex-module-decorators'
@Module({
name: 'counter',
stateFactory: true,
namespaced: true
})
export default class Auth extends VuexModule {
public counter: number = 5
@MutationAction({ mutate: ['counter'] })
async set() {
console.log(this.counter)
return { counter }
}
}
output: undefined
However, when I modify my code like this, it works:
@MutationAction({ mutate: ['counter'] })
async set() {
console.log((this.state as any).counter)
return { counter }
}
output: 5
If I set a value before trying to access it, everything works fine:
@MutationAction({ mutate: ['counter'] })
async set() {
this.counter = '20'
console.log(this.counter)
return { counter }
}
output: 20
Can someone offer guidance on how to properly work with this.counter
?