i have created gallery component in vue, which has lightbox with following code
<div id="lightbox" class="modal" v-if="photo !== null" v-show="showModal" @click.self="closeModal">
<div class="modal-content">
<div class="slide">
<div class="slide-number" v-if="cardsView">
{{ photos.findIndex((p) => p.id == photo.id) + 1 }} / {{ photos.length }}
</div>
<div class="slide-number" v-if="!cardsView">
{{ csSortedPhotos.findIndex((p) => p.id == photo.id) + 1 }} / {{ csSortedPhotos.length }}
</div>
<!-- <img :src="photo.s3Path" alt="Photo has not been loaded."
class="modal-img"
v-touch:swipe.right="prevSlide"
v-touch:swipe.left="nextSlide"
> -->
<img v-for="ph in photos" :src="ph.s3Path"
v-show="photo.id == ph.id" alt="Photo has not been loaded."
class="modal-img"
v-touch:swipe.right="prevSlide"
v-touch:swipe.left="nextSlide"
>
</div>
.
.
.
previously I used the commented out part to display photo in modal
<img :src="photo.s3Path" alt="Photo has not been loaded."
class="modal-img"
v-touch:swipe.right="prevSlide" v-touch:swipe.left="nextSlide"
>
however, i had to change it to this, because client wanted to be able to use nextSlide
function with zero delay
<img v-for="ph in photos" :src="ph.s3Path" v-show="photo.id == ph.id" alt="Photo has not been loaded."
class="modal-img"
v-touch:swipe.right="prevSlide" v-touch:swipe.left="nextSlide"
>
This works much better and photos are iterable quickly.
However, the next catch is that I assume vue considers this element unimportant (since v-show
on modal is false
by default) and starts loading all the images after the modal has been opened for first time.
This results in 1-4 seconds of wait after you click on the first photo to open.
My question is - do I assume correctly how vue works in this matter? And can I somehow tell vue, to load these elements right away with no delay?