Reputation: 20369
I have a responsive-menu component which I want to use named slots inside of this up my template markup:
<template>
<div class="responsive-menu">
<div class="menu-header">
<slot name="header"></slot>
</div>
</div>
</template>
Whenever I try my named slot like this it work perfectly fine:
<responsive-menu>
<h3 slot="header">Responsive menu header</h3>
</responsive-menu>
However as soon as I wrap it with a class nothing shows up anymore.
<responsive-menu>
<div class="container">
<h3 slot="header">Responsive menu header</h3>
</div>
</responsive-menu>
What is going on here? Shouldn't I just be able to wrap the named component? Which does it appear that my named slots need to be direct children of my Vue component?
Upvotes: 5
Views: 23231
Reputation: 51
You could use it like v-slot
because slot
syntax is deprecated as mentioned here:
<responsive-menu>
<div class="container">
<h3 v-slot:header>Responsive menu header</h3>
</div>
</responsive-menu>
or Alternatively, a shorthand:
<responsive-menu>
<div class="container">
<h3 #header>Responsive menu header</h3>
</div>
</responsive-menu>
Upvotes: 1
Reputation: 535
It works with Vue >= 2.6. Just upgrade vue and vue-template-compiler.
Upvotes: 2