I have an image slider using Vue.js with a setInterval function looping through 4 images, I have it working almost to my liking except on the last image clearInterval call there is too long of a delay before the image slider starts again on the 0 image index. Is there a way to go directly back to the first index / image smoother / quicker?
<script>
export default {
name: "Slider",
data() {
return {
currentSliderIndex: 0
};
},
mounted() {
setInterval(() => {
this.currentSliderIndex = this.currentSliderIndex + 1;
if (this.currentSliderIndex > 4) {
clearInterval();
this.currentSliderIndex = 0;
}
}, 4000);
}
};
</script>