@@ -8,64 +8,83 @@ export default {
8
8
< div class = " vue-pagination" >
9
9
< nav>
10
10
< ul class = " pagination" >
11
- < li class = {{disabled: this .pages . current_page === 1 }}>
11
+ < li class = {{disabled: this .currentPage === 1 }}>
12
12
< a href= " #" on- click= {(e ) => this .firstPage (e)}>< span aria- hidden= " true" > & laquo;& laquo;< / span>< / a>
13
13
< / li>
14
- < li class = {{ disabled: this .pages . current_page === 1 }}>
14
+ < li class = {{ disabled: this .currentPage === 1 }}>
15
15
< a href= " #" on- click= {(e ) => this .previous (e)}>< span aria- hidden= " true" > & laquo;< / span>< / a>
16
16
< / li>
17
17
{this .paginationItems }
18
- < li class = {{disabled: this .pages . current_page === this .pages . last_page }}>
18
+ < li class = {{disabled: this .currentPage === this .lastPage }}>
19
19
< a href= " #" on- click= {(e ) => this .next (e)}>< span aria- hidden= " true" > & raquo;< / span>< / a>
20
20
< / li>
21
- < li class = {{ disabled: this .pages . current_page === this .pages . last_page }}>
22
- < a href= " #" on- click= {(e ) => this .lastPage (e, this .pages . last_page )}>< span aria- hidden= " true" > & raquo;& raquo;< / span>< / a>
21
+ < li class = {{ disabled: this .currentPage === this .lastPage }}>
22
+ < a href= " #" on- click= {(e ) => this .goTolastPage (e, this .lastPage )}>< span aria- hidden= " true" > & raquo;& raquo;< / span>< / a>
23
23
< / li>
24
24
< / ul>
25
25
< / nav>
26
26
< / div>
27
27
)
28
28
},
29
- props: [' pages' ],
29
+ props: {
30
+ total: {
31
+ type: Number ,
32
+ default: 0
33
+ },
34
+ perPage: {
35
+ type: Number ,
36
+ default: 0
37
+ }
38
+ },
30
39
created () {
31
40
window .addEventListener (' keyup' , ({key}) => this .changePageWithKeyBoard (key))
32
41
},
42
+ data () {
43
+ return {
44
+ currentPage: 1
45
+ }
46
+ },
33
47
computed: {
34
48
items: DatasourceUtils .gettingItems ,
35
49
paginationItems () {
36
50
return this .items .map ((item , index ) => {
37
- return < li class = {{active: (this .pages . current_page === item)}}>
51
+ return < li class = {{active: (this .currentPage === item)}}>
38
52
< a href= " #" on- click= {(e ) => this .change (e, item)}> {item}< / a>
39
53
< / li>
40
54
})
55
+ },
56
+ lastPage () {
57
+ if (this .total === 0 ) return 1
58
+ return parseInt (((this .total - 1 ) / this .perPage ) + 1 )
41
59
}
42
60
},
43
61
methods: {
44
62
firstPage (e ) {
45
63
e .preventDefault ()
46
- if (this .pages . current_page !== 1 ) {
64
+ if (this .currentPage !== 1 ) {
47
65
this .change (e, 1 )
48
66
}
49
67
},
50
68
previous (e ) {
51
69
e .preventDefault ()
52
- if (this .pages . current_page !== 1 ) {
53
- this .change (e, -- this .pages . current_page )
70
+ if (this .currentPage !== 1 ) {
71
+ this .change (e, -- this .currentPage )
54
72
}
55
73
},
56
74
change (e , page ) {
57
75
e .preventDefault ()
76
+ this .currentPage = page
58
77
EventBus .$emit (' pagination-change' , page)
59
78
},
60
79
next (e ) {
61
80
e .preventDefault ()
62
- if (this .pages . current_page !== this .pages . last_page ) {
63
- this .change (e, ++ this .pages . current_page )
81
+ if (this .currentPage !== this .lastPage ) {
82
+ this .change (e, ++ this .currentPage )
64
83
}
65
84
},
66
- lastPage (e , page ) {
85
+ goTolastPage (e , page ) {
67
86
e .preventDefault ()
68
- if (this .pages . current_page !== this .pages . last_page ) {
87
+ if (this .currentPage !== this .lastPage ) {
69
88
this .change (e, page)
70
89
}
71
90
},
0 commit comments