0

I am trying to access nested property of store state data but it is undefined when I try to access. I have following data

const state = {
  entity: {
    initial: {valid: false},
    general: {valid: false},
    buildFiles: {valid: false},
    license: {valid: false},
    author: {valid: false},
  }
};
const getters = {
  ENTITY: (state: any): Submission => {
    return state.entity; // Works fine
  },
  INITIAL: (state) => {
    console.log(state.entity); // Prints observable with entity and properties
    console.log(state.entity.initial); // Prints undefined
    return state.entity.initial;
  },
  
};

All I am trying to do is use getters from the component. Is there any way I can access property intitial?

2
  • I don't see any problem in the vuex store so far. Can you please share how you access your getters in the component? Commented Oct 27, 2020 at 18:13
  • Are you sure you didn't overwrite the whole entity before checking getters? Commented Oct 27, 2020 at 18:38

1 Answer 1

1

I think you need return state as a function. And your getters needed some a little changes: Try some thing like this:

const state = () => ({
  entity: {
    initial: { valid: false },
    general: { valid: false },
    buildFiles: { valid: false },
    license: { valid: false },
    author: { valid: false },
  },
})
const getters = {
  ENTITY: (state) => (submission) => {
    return state.entity // Works fine
  },
  INITIAL: (state) => {
    console.log(state.entity) // Prints observable with entity and properties
    console.log(state.entity.initial) // Prints undefined
    return state.entity.initial
  },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.