D
D
danilr2019-04-25 08:11:23
Vue.js
danilr, 2019-04-25 08:11:23

How to run a method from a parent in a Vue child?

It is necessary to somehow run the method in the child when clicking in the parent - how can this be done? only without watch please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-04-25
@danilr

via ref :

<button @click="$refs.child.someMethod()">call child method</button>
<child-component ref="child"></child-component>

R
Rodion Almetov, 2019-04-25
@radar4ick

https://ru.vuejs.org/v2/guide/components-custom-ev...
Through $emit
in the parent in the methods: nameEvent(){ } in the child where you need to call the event (some function) this.$ emit('someEvent');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question