defineExpose()

Exposes selected properties to parent template refs.

Since Vue 3.0 Spec ↗

Syntax

defineExpose({ ... })

Parameters

NameTypeRequiredDescription
exposed object No Properties/methods to make available via a template ref.

Returns

void — Nothing; configures the public instance.

Examples

<script setup lang="ts">
import { ref } from 'vue';

const open = ref(false);
function show() {
  open.value = true;
}
defineExpose({ show });
</script>
<!-- parent -->
<!-- <Dialog ref="dlg" /> ; dlg.value?.show() -->

Notes

Components using `<script setup>` are closed by default; their bindings are not accessible via a template ref. Call defineExpose to whitelist a public API (methods, refs). It is a compiler macro and needs no import.