In my current project, I am facing a challenge with a parent component needing to call a method from one of its child components:
<template>
<div>
<button @click="callChildMethod">
<child-component ref="child" />
</div>
</template>
<script>
setup(props) {
const child = ref(null)
const callChildMethod = () => {
child.doSomething()
}
return {
child,
callChildMethod
}
}
</script>
The child component contains a method named doSomething
:
const doSomething = () => { console.log('calling method....') }
My project is based on VueJS3 and the Composition API, and I tried using a template ref to access the method in the child component. However, I am facing issues and can't figure out what I'm missing. If anyone has any insights or suggestions, I would greatly appreciate it. Thank you!