--- title: Provide Fallback Content for Slots impact: LOW impactDescription: Components without slot fallbacks may render empty or broken when content is not provided type: best-practice tags: [vue3, slots, fallback-content, component-design, reusability] --- # Provide Fallback Content for Slots **Impact: LOW** - Providing sensible default content inside `` elements makes components more resilient and user-friendly. Fallback content renders when no slot content is provided by the parent. ## Task Checklist - [ ] Add fallback content inside slot elements for optional slots - [ ] Use meaningful defaults that make sense standalone - [ ] Consider i18n for text fallbacks in internationalized apps - [ ] Document which slots have fallbacks and what they display **Without Fallback (fragile):** ```vue ``` ```vue ``` **With Fallback (resilient):** ```vue ``` ```vue Save Changes ``` ## Named Slots with Fallbacks ```vue ``` ## Complex Fallback Content Fallback content can include multiple elements and logic: ```vue ``` ## When to Use Fallbacks | Slot Purpose | Fallback Recommended? | Example | |--------------|----------------------|---------| | Button text | Yes | "Submit", "Click here" | | Icon slot | Yes | Default icon component | | Modal title | Yes | "Dialog" | | Required content area | No | Main content slot | | Customization only | Optional | Action buttons slot | ## Reference - [Vue.js Slots - Fallback Content](https://vuejs.org/guide/components/slots.html#fallback-content)