Child页面
<template>
<div>
</div>
</template>
<script setup>
import { ref } from 'vue'
const message = ref('Hello!')
// 使用defineExpose公开message属性
defineExpose({
message
})
</script>
Parent页面
<template>
<div>
<ChildComponent ref="childRef" />
<el-button @click="getChildMessage ">获取子页面的值</el-button>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import ChildComponent from './ChildComponent.vue'
const childRef = ref(null)
const getChildMessage = () => {
let childMessage = childRef.value.message
}
</script>