前端学习-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>
posted @ 2024-03-22 10:03  ayubene  阅读(10)  评论(0)    收藏  举报