E
E
Evgeny Zhurov2019-12-18 15:33:08
Vue.js
Evgeny Zhurov, 2019-12-18 15:33:08

How to pass the changed data of a specific store object to the component from vuex?

Good afternoon.
There is an array of elements in the store, on the basis of which the list is built. Each list item has a state switch for the specific item in that list. The list id is passed to the radio button. When the switch is triggered, I will dispatch the data to the store. The getter to receive looks like this
this.$store.dispatch('handler', payload)

getState: state => id => {
  return state.listings.find(el => el.id == id).is_edited //возвращает true или false
}

And finally, in the computed component, I get this getter . All this is triggered when the application is loaded. What should be done to get the changed value when the switch is triggered?
this.$store.getters.getState(this.item.id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2019-12-20
@Zhuroff

Try replacing the mutation with this:

startMutation(state, data) {
  const index = state.listings.findIndex(item => item.id === data.id)
  state.listings.splice(index, 1, {...state.listings[index], is_edited: true})
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question