Skip to content

Instantly share code, notes, and snippets.

@BrockReece
Created September 1, 2019 13:09
Show Gist options
  • Save BrockReece/2b1d4a330555673e31f491454024503e to your computer and use it in GitHub Desktop.
Save BrockReece/2b1d4a330555673e31f491454024503e to your computer and use it in GitHub Desktop.
<template>
<div class="container">
<img v-if="isOnScreen" width="25%" :src="src" @load="loaded">
</div>
</template>
<script>
import { useOnScreen } from "../hooks/screen";
import { useLazyLoad } from "../hooks/lazyLoad";
export default {
setup() {
const { isOnScreen } = useLazyLoad(useOnScreen());
return {
isOnScreen
};
},
name: "LazyLoadImage",
props: {
src: {
type: String,
default: "https://lorempixel.com/400/200/"
}
},
methods: {
loaded() {
console.log("lazy loaded");
}
}
};
</script>
<style scoped>
.container {
min-height: 10px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment