<!-- Child.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
const reset = () => { count.value = 0 }
// 只有这里列出的才能被父组件访问
defineExpose({ count, reset })
</script>
<!-- Parent.vue -->
<template>
<Child ref="childRef" />
<button @click="childRef.reset()">重置</button>
</template>
<script setup>
import { ref } from 'vue'
const childRef = ref(null)
</script>