Due to the Array.splice() function, only the first v-if is triggered even if the second one is the correct condition. When I console.log the photos object the number length of the 'photos' object gets smaller by increments of 4 until it's 0 hence why the first condition is hit. How do I stop this from happening to display the proper div ? Here is the body of my code :
<div v-if="(checkCount = 1)">
<Splide :options="{ rewind: true }" aria-label="Carousel Pictures">
<SplideSlide class="fs-800">
<div v-for="item in photos.splice(0, 4)" :key="item.id">
<a href="">
<img :src="item.img" alt="" />
<p>{{ item.text }}</p>
</a>
</div>
</SplideSlide>
</Splide>
</div>
<div v-else-if="(checkCount = 2)">
<Splide :options="{ rewind: true }" aria-label="Carousel Pictures">
<SplideSlide class="fs-800">
<div v-for="item in photos.splice(0, 4)" :key="item.id">
<a href="">
<img :src="item.img" alt="" />
<p>{{ item.text }}</p>
</a>
</div>
</SplideSlide>
<SplideSlide class="fs-800">
<div v-for="item in photos.splice(0, 4)" :key="item.id">
<a href="">
<img :src="item.img" alt="" />
<p>{{ item.text }}</p>
</a>
</div>
</SplideSlide>
</Splide>
</div>
Here is the data and condition:
data() {
return {
photos: [
{
img: "https://picsum.photos/300/300",
text: 1,
},
{
img: "https://picsum.photos/300/300",
text: 2,
},
{
img: "https://picsum.photos/300/300",
text: 3,
},
{
img: "https://picsum.photos/300/300",
text: 4,
},
{
img: "https://picsum.photos/300/300",
text: 5,
},
{
img: "https://picsum.photos/300/300",
text: 6,
},
{
img: "https://picsum.photos/300/300",
text: 7,
},
{
img: "https://picsum.photos/300/300",
text: 8,
},
],
};
},
computed: {
checkCount() {
if (this.photos.length <= 4) {
return 1;
} else if (this.photos.length > 5 && this.photos.length <= 8) {
return 2;
} else if (this.photos.length > 9 && this.photos.length <= 12) {
return 3;
} else {
return 4;
}
},
},