[Vuejs]-Rendering Vue slot elements in template loop

0👍

Typical, after searching for ages I find the solution just after posting my question. It’s very simple too.

Each slide in the loop can be rendered as a dynamic <component>

<script setup>
import { useSlots } from "vue";

import { Swiper, SwiperSlide } from 'swiper/vue';
import 'swiper/css';

const slots = useSlots();

console.log(slots.slides());
</script>

<template>
    <div>
        <swiper>
            <swiper-slide v-for="(slide, key) in slots.slides()" v-bind="props">
                <component :is="slide" />
            </swiper-slide>
        </swiper>
    </div>
</template>

<style scoped>
</style>

Leave a comment