1

there is a component with a ref like this:

<template>
  <custom-component
     ref="func"
  />
</template>

<script setup>
const func = ref();
</script>

and inside the component there is a function like this:

const helloWorld = () => {
    console.log('hello World');
}

how do i get accsess to helloWorld function from the parent component?

1 Answer 1

2

Assuming your child component is also using <script setup>, the component's definitions are closed by default (not exposed).

You can manually expose the method with defineExpose in the child component:

// CustomComponent.vue
<script setup>
const helloWorld = /*...*/

defineExpose({
  helloWorld
})
</script>

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.