Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Components as slot content Vue3

I wonder how to add components as slot content. Instead of doing it like:

<template v-slot:content>CONTENT HERE</template>

I’d like to pass a component.

PkDynModalCenter:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div class="...">
    <div id="modalIndicator" class="...">
        <slot name="content"></slot>
    </div>
</div>

Parent:

<PkDynModalCenter v-if="togglePayment" @closeModal="togglePayment = false">
        <PaymentTemplate :info="voucherInfo" name="content"></PaymentTemplate>
</PkDynModalCenter>

But it’s not displayed. Docs are very vague there…

>Solution :

Have a look at the docs for named slots: https://vuejs.org/guide/components/slots.html

You can only use your parent code with the default slot, so your PkDynModalCenter should look like this:

<div class="...">
    <div id="modalIndicator" class="...">
        <slot></slot> <!-- no name → default slot -->
    </div>
</div>

With your current code for the modal, you can only call it like you did in your first code snippet.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading