子组件
<script setup>
import { ref } from 'vue'
const a = 1
const b = ref(2)
// 像 defineExpose 这样的编译器宏不需要导入
defineExpose({ //暴露子组件的相关参数
a,
b
})
</script>
<template>
<div>
asddsa
</div>
</template>
父组件
<script setup>
import { ref, onMounted } from 'vue'
import Child from './components/Child.vue'
const child = ref(null)
onMounted(() => {
// child.value 是 <Child /> 组件的实例
console.log(child.value)
})
</script>
<template>
<Child ref="child" />
</template>