I have the following template:
<template>
<div v-if='isLoaded'>
<div @click='selectSight(index)' v-for='(sight, index) in sights'>
<img :src="'https://maps.googleapis.com/maps/api/place/photo?maxwidth=300&photoreference=' + sight.photos[0].photo_reference + '&key='">
</div>
</div>
</template>
I am wondering is it possible to somehow detect when all images have loaded so I could set isLoaded
to true when that happens? I want to avoid displaying the entire div until everything is loaded so I could avoid the flickering of the loading images ( some of them load faster, some of them slower ).
<script>
export default {
data(){
return {
sights: null,
isLoaded: false
}
},
mounted() {
axios.get('/getSights/' + this.lat + '/' + this.lng + '/' + this.type + '/' + this.range)
.then(response => {
this.sights = response.data.result.results
this.nextPageToken = response.data.result.next_page_token
}).catch((error) => console.log(error));
}
}
</script>
I tried:
var images = document.getElementsByClassName('sight-photos');
images.onload = function () {
console.log('hey')
}
However I don't see the console message when I tried:
var images = document.getElementsByClassName('sight-photos')[0];
images.onload = function () {
console.log('hey')
}
I do see the message so I assume you can't use onload on collection of images?