N
N
Nikita Kudinov2021-03-10 14:34:32
Vue.js
Nikita Kudinov, 2021-03-10 14:34:32

Why doesn't mounted work the first time?

There is a component, repeating components are loaded in it, to which the data in the object is passed. In the mounted method of the child component, the object is changed (a field is added), then when the button in the child component is pressed, the object is written to the global variable, but as I found, the original object is written, and after I change any letter in the child component, it will be rebuilt and immediately mounted worked and so every time. Why is that?

UPD:
as I found out, if you put the addition of a field into an object in setTimeout, then the field is added, but in the console, before the method of adding the field, it is displayed that the data has arrived.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Popov, 2021-03-11
@groog

If I understood you correctly, then you change (add a field) the object that came from the parent in the child element. It’s bad to do this, since js is passed links and all participants have the same object.
Also, adding a property to an already created object directly does not set reactivity. It is correct to add fields via Vue.set .
But once again, this is clearly an architectural problem. Attach the code, we'll see

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question