T
T
tenaro2019-01-28 18:46:32
Vue.js
tenaro, 2019-01-28 18:46:32

How to add a snapshot of the current state in Vuex?

In store vuex:

const state = {
  filter_list: [], - тут хочу хранить слепки
  filter: { - текущие состояние 2х инпутов, связано через v-model
  input1:'',
  input2:''
  }
}

I want to save the current filter value as a new filter_list element
in a mutation on the button, something like this:
FILTER_SAVE (state) {
  state.filter_list.push({filter: state.filter})
}

the problem is reactivity, when changing the texts in the input, the old recorded objects change
how to organize it correctly? the real challenge is to let the user save their filters

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-01-28
@tenaro

the problem is reactivity, when changing the texts in the input, the old recorded objects change

Yes Yes. This is how it turns out: don't learn JS, use frameworks.
state.filter_list.push({ ...state.filter })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question