0
0
Vueframework~20 mins

Slots for content distribution in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Slot Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will be rendered by this Vue component using slots?

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?

ADefault Main
BMain Content
CHeader Content
DFooter Content
Attempts:
2 left
💡 Hint

Remember that the default slot is used when no name is specified.

📝 Syntax
intermediate
1:30remaining
Which option correctly defines a named slot in Vue 3?

Choose the correct syntax to define a named slot called 'sidebar' inside a Vue component template.

A&lt;slot #sidebar&gt;&lt;/slot&gt;
B&lt;slot sidebar&gt;&lt;/slot&gt;
C&lt;slot :name="sidebar"&gt;&lt;/slot&gt;
D&lt;slot name="sidebar"&gt;&lt;/slot&gt;
Attempts:
2 left
💡 Hint

Named slots use the name attribute on the <slot> element.

state_output
advanced
2:00remaining
What is the output when using scoped slots with props?

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?

A<p>Name: {{ user.name }}</p>
BNo user
C<p>Name: Alice</p>
DError: user is undefined
Attempts:
2 left
💡 Hint

Scoped slots pass data from child to parent via slot props.

🔧 Debug
advanced
2:30remaining
Why does this slot content not render as expected?

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>?

ABecause the &lt;p&gt; element is not inside a &lt;template #default&gt; slot wrapper
BBecause the Modal component does not define a default slot
CBecause the slot name 'default' is missing on the &lt;p&gt; element
DBecause named slots cannot be mixed with default slot content
Attempts:
2 left
💡 Hint

Default slot content must be wrapped in a <template> with no name or #default.

🧠 Conceptual
expert
3:00remaining
How does Vue 3's new syntax improve content distribution?

Vue 3 introduced changes to slot syntax and usage. Which statement best describes a key improvement in Vue 3 slots compared to Vue 2?

AVue 3 allows multiple root nodes inside slot content without wrapping elements
BVue 3 requires all slots to be named explicitly, removing default slots
CVue 3 slots no longer support passing props from child to parent
DVue 3 slots must be declared inside the script setup block
Attempts:
2 left
💡 Hint

Think about how Vue 3 improved template flexibility.