Function defineExpose()
Components using <script setup>
are closed by
default.
To explicitly expose properties in a
<script setup>
component, use the defineExpose
compiler macro:
<script setup>
import { ref } from 'vue'
const a = 1
const b = ref(2)
defineExpose({
a,
b
})
</script>
When a parent gets an instance of this component
via template refs, the retrieved instance will be
of the shape { a: number, b: number } (refs are
automatically unwrapped just like on normal
instances).