Vuex calls this.$store.state.xx.xx undefind in the component

state.js
state:{
    data:{}
}

mutation.js
type.data (state, arg) {
    return state.data = arg
}

action.js
commit(types.data, {a: 111, b: 222})

getters.js
export const data = (state) => {
    return state.data
}

is called in the methods method of the component, not in the template template.

this.$store.getters.data       //{a:111, b:222}
this.$store.state.data       //{a:111, b:222}

,.
this.$store.getters.data.a     // undefined
this.$store.state.data.a       // undefined

Please tell me how to call ~ directly in the component?

Nov.01,2021

landlord, you can refer to this article, Portal

. < hr >

here is the code for my local test, and the conclusion is that it is all values that can be taken

.

/ / vuex related
/ / store.js


state.js
state: {
   remind: {}
}

mutation_types.js
export const REMAIND = 'REMAIND'

mutation.js
[type.REMIND] (state, arg) {
    state.remind = arg
}

actions.js
getdata ({state, commit}, arg) {
    ...,
    commit(types.REMAIND, {free: res.data.freeNum, queue: res.data.queueNum})
}


getters.js
export const remind = (state) => {
    return state.remind
}

test.vue
methods:{
   submit () {
       this.$store.dispatch('getData')
       console.log(this.$store.getters.remind)       // {obj....arry(0)}
       console.log(this.$store.getters.remind.free)   // undefined
       console.log(this.$store.getters.remind.queue)  // undefined
   }
}
the first click on submit is empty
the second click on submit is worth it.
both state, and getters are like this. Why?
Menu