子组件可以通过 props 从父组件接受动态数据
ChildComp.vue
<script setup>
const props = defineProps({
msg: String
})
</script>
<template>
<h2>{{ msg || 'No props passed yet' }}</h2>
</template>
App.vue
<script setup>
import { ref } from 'vue'
import ChildComp from './ChildComp.vue'
const text = ref('我是从父级传递过来的数据')
</script>
<template>
<!-- 变量(text)只能通过ref来定义,不能直接传字符串 -->
<ChildComp :msg="text" />
</template>