Skip to content

Instantly share code, notes, and snippets.

@raae
Last active September 1, 2017 15:02
Show Gist options
  • Save raae/72b4ccc207214b1c84d8e0e1fd341aa3 to your computer and use it in GitHub Desktop.
Save raae/72b4ccc207214b1c84d8e0e1fd341aa3 to your computer and use it in GitHub Desktop.
Super simple vue snippet for lazy loading images
<template>
<transition name="fade">
<img v-if="imageSrc" :src="imageSrc" />
</transition>
</template>
<script>
export default {
props: [
'src'
],
data() {
return {
imageSrc: null
}
},
mounted() {
let image = new Image()
image.src = this.src
image.onload = () => {
this.imageSrc = this.src
}
}
}
</script>
<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
transition: all 250ms ease-in-out;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
transform: scale(0.95);
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment