V
V
Valery V.2019-02-05 19:42:28
Vue.js
Valery V., 2019-02-05 19:42:28

How to update object properties in vuex?

Good afternoon!
How to correctly update an object (or its individual properties) in store vuex?
Let's say there is an object in store

state:{
  params: {
    prop1: {},
    prop2: {},
    prop3: {}
  }
}

case1: get the params object and replace it completely (possibly with a change in its structure).
case2: get a params object and replace one property prop1.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2019-02-05
@OlegOleg1980

mutations:
case1:

setParams (state, params) {
    state.params = params
}

case2:
setParamsProperty (state, obj) {
    state.params = {...state.params, ...obj }
}

where objis an object of the form:
{
  prop1: value1
}

or like this for example:
{
  prop1: value1,
  prop2: value2
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question