Vue best practice for calling a method in a child component

One easy way is to do this:

<!-- parent.vue -->
<template>
    <button @click="$refs.myChild.sayHello()">Click me</button>
    <child-component ref="myChild" />
</template>

Simply create a ref for the child component, and you will be able to call the methods, and access all the data it has.

Leave a Comment