A
A
Aleksandr2018-06-07 15:43:27
Vue.js
Aleksandr, 2018-06-07 15:43:27

Why is the getter not working?

In general, the situation is the following.
When I start the project, an error occurs in the function

return this.getTransportFields.reduce((data, f) => ({ ...data, [f.name]: f.value }), {})

She flies out because
console.log(this.getTransportFields) // undefined

getTransportFields() {
    return this.$store.getters['getTransportFields']
},


Here is the getter
getTransportFields(state) {
    return state.FIELDS.formFieldsMap
  },


The state.FIELDS.formFieldsMapdata is

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-06-07
@Sashjkeee

The state.FIELDS.formFieldsMapdata is

Do they really lie? - maybe they do not lie, but are loaded by means of a request to the database or somewhere else. In the meantime, it has not loaded, FIELDS is an empty object, it does not have any formFieldsMap property. Accordingly, the getter returns undefined. Could this be?
UPD. Taken from the comments:
You can return a stub if there is nothing, for example:
getters: {
  transportFields: state => state.FIELDS.formFieldsMap || [],
  ...

Better yet, create the desired property in FIELDS in advance, with an empty array as the initial value.

K
Koteezy, 2018-06-07
@Koteezy

Try the name of the getter without get?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question