Answer the question
In order to leave comments, you need to log in
Get data from child component when parent method is called?
Actually the question is in the title.
I have a wrapper component and two data components inside.
How, when calling method-1 (located in the parent), get data from child component 1?
And when calling method-2(located in parent) get data from child component 2?
i.e. the scheme is something like this
<parent-component>
<child-component-1/>
<child-component-2/>
<btn @click="method1"/>
<btn @click="method2"/>
</parent-component>
Answer the question
In order to leave comments, you need to log in
Well, first of all, it shouldn't be like that.
Components communicate through props and events: props above, events below.
Has the data in component 1 changed? He sent an event update
, and the parent caught it and did something.
If this is some kind of multi-component structure, where child components should always be in the parent, then the parent does provide
, the children do inject
and thus keep a common set of data / methods.
Well ref
, you can also use it, but here you should think over the architecture with public and internal methods so that support does not turn into hell.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question