1
1
2
2
<template >
3
- <div class =" movies" >
4
- <div class =" movie" v-for =" movie in movies" :key =" movie.id" >
5
- <img :src =" movie.img" />
6
- </div >
3
+ <div >
4
+ <div class =" movies" >
5
+ <div class =" movie" v-for =" movie in movies" :key =" movie.id" >
6
+ <img :src =" movie.img" />
7
+ </div >
8
+ </div >
9
+ <a @click =" nextHandler()" class =" next" >Next</a >
7
10
</div >
8
11
</template >
9
12
10
13
<script lang="ts">
11
14
import Vue from " vue" ;
12
15
import InfiniteAjaxScroll from ' @webcreate/infinite-ajax-scroll' ;
13
16
17
+ const catalog = [
18
+ {
19
+ title: " The Matrix" ,
20
+ img: " https://media-cache.cinematerial.com/p/500x/uq49lqmo/the-matrix-movie-poster.jpg?v=1548664065"
21
+ },
22
+ {
23
+ title: " Jurrasic Park" ,
24
+ img: " https://media-cache.cinematerial.com/p/500x/4ubyv2go/jurassic-park-movie-poster.jpg?v=1456328203"
25
+ },
26
+ {
27
+ title: " Indiana Jones" ,
28
+ img: " https://cdn.shopify.com/s/files/1/0057/3728/3618/products/609df06d7c2b5fb3125f16a7e4e34152_592ed277-d9d9-4400-af4b-f793370e5f54_480x.progressive.jpg?v=1573616163"
29
+ },
30
+ {
31
+ title: " 2001, A space odyssey" ,
32
+ img: " https://cdn.shopify.com/s/files/1/1416/8662/products/2001_a_space_odyssey_french_grande_linen_original_film_art_f_1200x.jpg?v=1587685085"
33
+ }
34
+ ]
35
+
36
+ let ias = null ;
37
+
14
38
export default Vue .extend ({
15
39
data() {
16
40
return {
17
- movies: [
18
- {
19
- id: 1 ,
20
- title: " The Matrix" ,
21
- img: " https://media-cache.cinematerial.com/p/500x/uq49lqmo/the-matrix-movie-poster.jpg?v=1548664065"
22
- },
23
- {
24
- id: 2 ,
25
- title: " Jurrasic Park" ,
26
- img: " https://media-cache.cinematerial.com/p/500x/4ubyv2go/jurassic-park-movie-poster.jpg?v=1456328203"
27
- },
28
- {
29
- id: 3 ,
30
- title: " Indiana Jones" ,
31
- img: " https://cdn.shopify.com/s/files/1/0057/3728/3618/products/609df06d7c2b5fb3125f16a7e4e34152_592ed277-d9d9-4400-af4b-f793370e5f54_480x.progressive.jpg?v=1573616163"
32
- }
33
- ]
41
+ movies: []
34
42
};
35
43
},
36
44
mounted() {
37
- window .ias = new InfiniteAjaxScroll (' .movies' , {
38
- item: ' .movie' ,
39
- next : () => {
40
- console .log (" Next" )
41
- },
42
- pagination: false ,
43
- bind: false
44
- });
45
-
46
- setTimeout (() => {
47
- ias .bind ();
48
- }, 5000 )
45
+ // Simulate initial load
46
+ Promise .all ([
47
+ this .loadNewMovie (),
48
+ this .loadNewMovie (),
49
+ this .loadNewMovie (),
50
+ this .loadNewMovie ()
51
+ ]).then (() => {
52
+ ias = new InfiniteAjaxScroll (' .movies' , {
53
+ item: ' .movie' ,
54
+ pagination: false ,
55
+ });
56
+
57
+ ias .on (' hit' , () => {
58
+ console .log (" hit!!!" )
59
+ this .loadNewMovie ()
60
+ })
61
+ })
62
+ },
63
+ methods: {
64
+ loadNewMovie() {
65
+ return new Promise ((resolve ) => {
66
+ // Simulate loading of new movie
67
+ setTimeout (() => {
68
+ const index = Math .round ((Math .random () * (catalog .length - 1 )));
69
+ const movie = {... catalog [index ], id: this .movies .length + 1 };
70
+
71
+ this .movies .push (movie )
72
+ resolve ()
73
+ }, 2000 )
74
+ })
75
+ },
76
+ nextHandler() {
77
+ this .loadNewMovie ()
78
+ }
49
79
}
50
80
});
51
81
</script >
52
82
53
83
<style lang="scss" scoped>
54
-
55
- </style >
84
+ .movie {
85
+ margin : 20px 0 ;
86
+ padding : 20px 20px ;
87
+ width : 300px ;
88
+ background-color : #ff0000 ;
89
+ img {
90
+ width : 100% ;
91
+ }
92
+ }
93
+ </style >
0 commit comments