前端学习-vue学习012-插槽
父组件还可以通过插槽 (slots) 将模板片段传递给子组件:
App.vue
<script setup>
import { ref } from 'vue'
import ChildComp from './ChildComp.vue'
const msg = ref('from parent')
</script>
<template>
<ChildComp>{{ msg }}</ChildComp>
</template>
ChildComp.vue,页面展示‘from parent’
<template>
<slot>Fallback content</slot>
</template>

浙公网安备 33010602011771号