This example shows a Card component with three slots: header, default body, and footer.
The parent App.vue uses named slots to put a title in the header, some text in the body, and a button in the footer.
If any slot content was missing, the card would show its default content instead.
<!-- Card.vue -->
<template>
<div class="card">
<header class="card-header">
<slot name="header">Default Header</slot>
</header>
<section class="card-body">
<slot>Default body content</slot>
</section>
<footer class="card-footer">
<slot name="footer">Default Footer</slot>
</footer>
</div>
</template>
<style scoped>
.card {
border: 1px solid #ccc;
padding: 1rem;
border-radius: 0.5rem;
max-width: 300px;
}
.card-header, .card-footer {
background-color: #f0f0f0;
padding: 0.5rem;
font-weight: bold;
}
.card-body {
margin: 1rem 0;
}
</style>
<!-- App.vue -->
<template>
<Card>
<template #header>
<h2>Welcome!</h2>
</template>
<p>This is the main content inside the card.</p>
<template #footer>
<button @click="alert('Clicked!')">Click me</button>
</template>
</Card>
</template>
<script setup>
import Card from './Card.vue'
</script>