作用:暴露数据或者方法供父组件使用,数据不会丢失响应式功能
1. person.vue
<script setup lang="ts">
import { ref,defineExpose } from 'vue'
let age = ref(18)
defineExpose({
age
})
</script>
2. App.vue
<script lang="ts" setup>
import {ref} from 'vue'
import Person from './components/Person.vue'
let person = ref()
setTimeout(()=>{
console.log(person.value.age); // 18
},1000)
</script>
<template>
<Person ref="person"/>
</template>