I'm creating my own carousel where images are added by <img>. I think that the method of creating carousel component in vue is way more flexible because I want to add inside LightBox component inside my carousel's slots
This is my parent component carousel
<template>
<div class="carousel">
{{ slides }}
<slot></slot>
</div>
</template>
<script>
import { ref } from 'vue';
export default{
data(){
return{
Currentslide: 0,
}
},
setup(props, {slots}){
const slides=ref(slots.default().map((slides) => slides.props.id))
return{
slides,
}
}
}
</script>
This is my child component slide
<template>
<div class="slide">
<slot/>
</div>
</template>
<script>
</script>
<template>
<Carousel>
<Slide id="1">1243423</Slide>
<Slide id=2>
1231
</Slide>
<Slide id="3">r445</Slide>
</Carousel>
</template>
<script>
import Carousel from "../../components/Reusable components/Carousel.vue"
import Slide from "../../components/Reusable components/Slide.vue"
export default{
components:{
Carousel,
Slide
}
}
Using the inefficient method in the world, I somehow can create an array of slots' indexes. But this is the worst solution to this problem. So, I want to explore another way of extracting IDs from slots in Vue.js