0 day streak
javascript / intermediate
Snippet

Explicitly Exposing Component APIs with defineExpose

Components using <script setup> are private by default. Parents cannot access internal methods via template refs unless they are explicitly exposed using the defineExpose macro.

snippet.js
javascript
1
2
const resetForm = () => { /* logic */ };
defineExpose({ resetForm });
vue
Breakdown
1
const resetForm = () => {
An internal function that performs a specific action within the child component.
2
defineExpose({ resetForm });
Make the function public so it can be called by a parent component via a ref.