Pass function from Parent to Child, where I can pass arguments also in Vue/Nuxt 3 Composition API
Parent Component
</script setup>
<template>
<div>
<ChildComponent :handleButtonClick="handleButtonClick" />
</div>
</template>
<script setup>
import ChildComponent from './ChildComponent.vue'
const handleButtonClick = (data) => {
console.log('Button clicked in child component',data)
}
</script>
Child Component
<template>
<button @click="handleButtonClick(1)">Click Me</button>
</template>
<script setup>
import { defineProps } from 'vue'
const props = defineProps({
handleButtonClick: {
type: Function,
required: true
}
})
</script>
Error I’m getting when calling the fn in child
TypeError: _ctx.handleButtonClick is not a function