Skip to content

Instantly share code, notes, and snippets.

@fraaalk
Created November 14, 2017 16:01
Show Gist options
  • Select an option

  • Save fraaalk/b033fb87b954a6046eb2190f15c2c113 to your computer and use it in GitHub Desktop.

Select an option

Save fraaalk/b033fb87b954a6046eb2190f15c2c113 to your computer and use it in GitHub Desktop.
lazy rendering of a movie list
<template>
<ul class="ui-list ui-list--movies">
<li
v-for="(movie, i) in movies"
:key="i">
<Movie :shows="movie">
</Movie>
</li>
</ul>
</template>
<script>
export default {
data() {
return {
showGroups: [50] // 50 movies in the array array (create alot of dom nodes)
}
},
computed: {
splitGroupSize() {
return 4;
},
lazyMovies() {
return this.showGroups.slice(this.splitGroupSize);
},
movies() {
return this.showGroups.slice(0, this.splitGroupSize);
}
},
methods: {
renderLazy() {
window.removeEventListener('touchstart', this.renderLazy);
window.removeEventListener('mousemove', this.renderLazy);
this.lazyMovies.forEach(movie => {
this.movies.push(movie);
});
},
},
mounted() {
window.addEventListener('touchstart', this.renderLazy);
window.addEventListener('mousemove', this.renderLazy);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment