S
S
sir_pounce2021-02-10 15:13:27
Vue.js
sir_pounce, 2021-02-10 15:13:27

How to call child component method?

You need to call a method from a child component if the child component is the same component as the parent.
For example:

<some-component>
  <another-component>
    <some-component></some-component>
  </another-component>
  <another-component>
    <some-component>
      <some-component />
    </some-component>
  </another-component>
<some-component></some-component>
</some-component>


It is necessary that when a component is called in the root some-component - the same method would work for other some-component components that are children of the root some-component.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2021-02-10
@AlexeyCaTHaR

There was such a question at the interview)
I solved it through ref. (here there is an implementation https://github.com/AlexeyCaTHaR/testAssignment )
It was proposed to forward the method and everything that is needed for this through provide / inject.
There is an option to enumerate vm.$children and, depending on the name of the component, register it in the "pool" of child components and force the method to run

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question