I am facing an issue with utilizing an array of objects in my Vuex state to set a default value for another parameter, specifically for mainAccount
:
For instance:
const store = new Vuex.Store({
state: {
AccountNums: [
{
label: 'Mister1',
value: '1234567890'
},
{
label: 'Mister2',
value: '9876543210'
}
],
mainAccount: this.state.AccountNums[1].value //attempting to use the value from the object here
}
However, I keep encountering an error message that says:
Cannot read property 'state' of undefined
When I eliminate the this
keyword, a different error appears:
'state' is not defined
How should I go about resolving this?
It's important to note that the AccountNums
object needs to stay inside my Vuex state because it will be accessed by many components.
Thank you!