File tree 6 files changed +89
-14
lines changed
6 files changed +89
-14
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default {
13
13
pokeList: [],
14
14
prev: " " ,
15
15
next: " " ,
16
- isLoading: false
16
+ isLoading: false ,
17
+ page: 1
17
18
};
18
19
},
19
20
created () {
@@ -22,6 +23,11 @@ export default {
22
23
mounted () {
23
24
this .scroll ();
24
25
},
26
+ watch: {
27
+ page (num ) {
28
+ this .fetchData (this .next );
29
+ }
30
+ },
25
31
methods: {
26
32
fetchData (url = INITIAL_DOMAIN ) {
27
33
this .isLoading = true ;
@@ -32,24 +38,24 @@ export default {
32
38
this .prev = obj .prev ;
33
39
this .next = obj .next ;
34
40
this .pokeList = this .pokeList .concat (obj .list );
35
- }, 500 );
41
+ }, 600 );
36
42
})
37
43
.finally (_ => {
38
44
setTimeout (_ => {
39
45
this .isLoading = false ;
40
- }, 500 );
46
+ }, 600 );
41
47
});
42
48
},
43
49
scroll () {
44
- window . onscroll = () => {
50
+ document . addEventListener ( " scroll " , () => {
45
51
let bottomOfWindow =
46
52
document .documentElement .scrollTop + window .innerHeight ===
47
53
document .documentElement .offsetHeight ;
48
54
49
55
if (bottomOfWindow) {
50
- this .fetchData ( this . next ) ;
56
+ this .page ++ ;
51
57
}
52
- };
58
+ }) ;
53
59
}
54
60
}
55
61
};
Original file line number Diff line number Diff line change 2
2
<div
3
3
v-infinite-scroll =" fetchData"
4
4
infinite-scroll-disabled =" busy"
5
- infinite-scroll-distance =" 500 "
5
+ infinite-scroll-distance =" 1200 "
6
6
>
7
7
<List :list =" pokeList" />
8
8
</div >
@@ -28,7 +28,6 @@ export default {
28
28
methods: {
29
29
fetchData (url = INITIAL_DOMAIN ) {
30
30
this .isLoading = true ;
31
- console .log (this .next );
32
31
common
33
32
.fetchList (this .next || url)
34
33
.then (obj => {
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div >Loding... </div >
2
+ <div class = " loading-image-wrapper " >< LoadingSvg1 class = " loading-image " /> </div >
3
3
</template >
4
4
5
5
<script >
6
- export default {};
6
+ import LoadingSvg1 from " ./svg/SvgLoading.vue" ;
7
+
8
+ export default {
9
+ components: { LoadingSvg1 }
10
+ };
7
11
</script >
8
12
9
- <style ></style >
13
+ <style >
14
+ .loading-image-wrapper {
15
+ display : flex ;
16
+ justify-content : center ;
17
+ align-items : center ;
18
+ }
19
+ </style >
Original file line number Diff line number Diff line change @@ -32,12 +32,12 @@ export default {
32
32
this .prev = obj .prev ;
33
33
this .next = obj .next ;
34
34
this .pokeList = this .pokeList .concat (obj .list );
35
- }, 200 );
35
+ }, 600 );
36
36
})
37
37
.finally (_ => {
38
38
setTimeout (_ => {
39
39
this .isLoading = false ;
40
- }, 200 );
40
+ }, 600 );
41
41
});
42
42
},
43
43
onClickMoreBtn (e ) {
Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ export default {
29
29
.then (data => {
30
30
this .pokemon = data;
31
31
})
32
- .finally (_ => (this .isLoading = false ));
32
+ .finally (_ => {
33
+ setTimeout (_ => {
34
+ this .isLoading = false ;
35
+ }, 1200 );
36
+ });
33
37
}
34
38
};
35
39
</script >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <svg
3
+ version =" 1.1"
4
+ xmlns =" http://www.w3.org/2000/svg"
5
+ xmlns:xlink =" http://www.w3.org/1999/xlink"
6
+ x =" 0px"
7
+ y =" 0px"
8
+ width =" 30px"
9
+ height =" 8px"
10
+ viewBox =" 0 0 30 8"
11
+ enable-background =" new 0 0 30 8"
12
+ xml:space =" preserve"
13
+ >
14
+ <rect x =" 0" y =" 0" width =" 8" height =" 8" fill =" red" opacity =" .2" >
15
+ <animate
16
+ attributeName =" opacity"
17
+ attributeType =" XML"
18
+ values =" .2 ; 1; .2"
19
+ begin =" 0s"
20
+ dur =" .6s"
21
+ repeatCount =" indefinite"
22
+ id =" first"
23
+ />
24
+ </rect >
25
+
26
+ <rect x =" 10" y =" 0" width =" 8" height =" 8" fill =" red" opacity =" .2" >
27
+ <animate
28
+ attributeName =" opacity"
29
+ attributeType =" XML"
30
+ values =" .2 ; 1; .2"
31
+ begin =" first.begin + .15s"
32
+ dur =" .6s"
33
+ repeatCount =" indefinite"
34
+ id =" second"
35
+ />
36
+ </rect >
37
+
38
+ <rect x =" 20" y =" 0" width =" 8" height =" 8" fill =" red" opacity =" .2" >
39
+ <animate
40
+ attributeName =" opacity"
41
+ attributeType =" XML"
42
+ values =" .2 ; 1; .2"
43
+ begin =" second.begin + .15s"
44
+ dur =" .6s"
45
+ repeatCount =" indefinite"
46
+ id =" third"
47
+ />
48
+ </rect >
49
+ </svg >
50
+ </template >
51
+
52
+ <script >
53
+ export default {};
54
+ </script >
55
+
56
+ <style ></style >
You can’t perform that action at this time.
0 commit comments