K
K
Konstantin Tolmachev2020-01-24 09:50:14
Vue.js
Konstantin Tolmachev, 2020-01-24 09:50:14

How to make updating an object inside an array reactive?

Good afternoon, colleagues. Something got confused.
The question is how to make a reactive update of an object placed in an array.
For example we have a structure:

data: function () {
            return {  
  list: [
           {param1: 'data',  param2 : 'qwer' ...}, 
           {param1: 'data2' param2: 'qwer' ...}
          ]
}}

How can param1 and param2 be changed and tracked?
The documentation says about Vue.set, but there is a construction (element, index, value).
That is, you can only change the object itself by index in the array, and not its properties. Maybe I'm stupid, but I just can't figure out how to update directly without a proxy object that needs to be filled with data and already assigned.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-01-24
@dark_tke

In fact, set is not needed at all in this case. Those properties that are in the object in data at the time the component instance is created become reactive by default: tyk .
Set should be used only for those properties that did not exist yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question