-
-
Save fraaalk/b033fb87b954a6046eb2190f15c2c113 to your computer and use it in GitHub Desktop.
lazy rendering of a movie list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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