How to expose methods in Vue 3 with defineExpose
Thursday, March 26, 2026
In Vue 3 <script setup>, all bindings are private by default — parent components cannot access child component methods or data using template refs unless you explicitly expose them with defineExpose.
As the creator of CoreUI with Vue development experience since 2014, I use defineExpose in CoreUI Vue components that need to provide imperative APIs, such as dialog open() and close() methods or form reset() and validate() methods.
Without defineExpose, a parent’s childRef.value.open() call fails silently because the method is not exposed.
This is intentional — <script setup> components are encapsulated by default, and defineExpose is an explicit contract of the public API.