F
F
fessss2020-10-01 19:33:23
Vue.js
fessss, 2020-10-01 19:33:23

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>


Well, accordingly, you need to get data from child-component

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-10-04
@fessss

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 injectand 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.

A
Alexey Yarkov, 2020-10-01
@yarkov Vue.js

Use $ref

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question