Consider the following Vue component usage:
<BaseLayout>
<template #header>Header Content</template>
<template #default>Main Content</template>
<template #footer>Footer Content</template>
</BaseLayout>And the BaseLayout component template:
<header><slot name="header">Default Header</slot></header>
<main><slot>Default Main</slot></main>
<footer><slot name="footer">Default Footer</slot></footer>What will be the rendered output inside the <main> element?
Remember that the default slot is used when no name is specified.
The <slot> without a name is the default slot. The content inside <template #default> replaces this slot. So <main> will render 'Main Content'.
Choose the correct syntax to define a named slot called 'sidebar' inside a Vue component template.
Named slots use the name attribute on the <slot> element.
The correct way to define a named slot is using <slot name="slotName">. Other options are invalid syntax.
Given the following parent component usage:
<UserCard>
<template #default="{ user }">
<p>Name: {{ user.name }}</p>
</template>
</UserCard>And the UserCard component template:
<slot :user="{ name: 'Alice' }">No user</slot>What will be rendered inside the UserCard?
Scoped slots pass data from child to parent via slot props.
The slot passes an object with user.name = 'Alice'. The parent template uses this prop to render the name.
Consider this parent usage:
<Modal>
<template #header>
Modal Header
<p>Modal Body</p>
</template>
</Modal>And the Modal component template:
<div class="modal">
<header><slot name="header">Default Header</slot></header>
<main><slot>Default Body</slot></main>
</div>Why is <p>Modal Body</p> not rendered inside <main>?
Default slot content must be wrapped in a <template> with no name or #default.
Only content inside a <template #default> or direct children without a slot name are passed to the default slot. Plain elements outside templates are treated as normal children and ignored by slots.
Vue 3 introduced changes to slot syntax and usage. Which statement best describes a key improvement in Vue 3 slots compared to Vue 2?
Think about how Vue 3 improved template flexibility.
Vue 3 supports fragments, so slot content can have multiple root nodes without extra wrappers, making templates cleaner and more flexible.