File tree 2 files changed +17
-4
lines changed
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,8 @@ export default {
37
37
},
38
38
data () {
39
39
return {
40
- loading: true
40
+ loading: true ,
41
+ pageNumber: 1
41
42
}
42
43
},
43
44
computed: {
@@ -50,6 +51,18 @@ export default {
50
51
this .loading = false ;
51
52
})
52
53
54
+ let vm = this ;
55
+ $ (window ).scroll (function () {
56
+ if (($ (window ).innerHeight () + $ (window ).scrollTop ()) >= $ (" body" ).height ()) {
57
+ if (vm .loading === false ) {
58
+ vm .loading = true
59
+ vm .pageNumber ++
60
+ vm .$store .dispatch (' getRepositories' , vm .pageNumber ).then (() => {
61
+ vm .loading = false
62
+ })
63
+ }
64
+ }
65
+ });
53
66
}
54
67
}
55
68
</script >
Original file line number Diff line number Diff line change @@ -29,12 +29,12 @@ export const store = new Vuex.Store({
29
29
mutations : {
30
30
getRepositories ( state , payload ) {
31
31
this . state . repositories = this . state . repositories . concat ( payload )
32
- return this . state . repositories
32
+ return this . state . repositories . concat ( payload )
33
33
}
34
34
} ,
35
35
actions : {
36
- getRepositories ( context ) {
37
- return axios . get ( `https://api.github.com/search/repositories?q=created:>2017-10-22&sort=stars&order=desc` )
36
+ getRepositories ( context , page ) {
37
+ return axios . get ( `https://api.github.com/search/repositories?q=created:>2017-10-22&sort=stars&order=desc&page= ${ page } ` )
38
38
. then ( ( res ) => {
39
39
context . commit ( 'getRepositories' , res . data . items )
40
40
} )
You can’t perform that action at this time.
0 commit comments