@@ -8,64 +8,83 @@ export default {
88 < div class = " vue-pagination" >
99 < nav>
1010 < ul class = " pagination" >
11- < li class = {{disabled: this .pages . current_page === 1 }}>
11+ < li class = {{disabled: this .currentPage === 1 }}>
1212 < a href= " #" on- click= {(e ) => this .firstPage (e)}>< span aria- hidden= " true" > & laquo;& laquo;< / span>< / a>
1313 < / li>
14- < li class = {{ disabled: this .pages . current_page === 1 }}>
14+ < li class = {{ disabled: this .currentPage === 1 }}>
1515 < a href= " #" on- click= {(e ) => this .previous (e)}>< span aria- hidden= " true" > & laquo;< / span>< / a>
1616 < / li>
1717 {this .paginationItems }
18- < li class = {{disabled: this .pages . current_page === this .pages . last_page }}>
18+ < li class = {{disabled: this .currentPage === this .lastPage }}>
1919 < a href= " #" on- click= {(e ) => this .next (e)}>< span aria- hidden= " true" > & raquo;< / span>< / a>
2020 < / 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>
2323 < / li>
2424 < / ul>
2525 < / nav>
2626 < / div>
2727 )
2828 },
29- props: [' pages' ],
29+ props: {
30+ total: {
31+ type: Number ,
32+ default: 0
33+ },
34+ perPage: {
35+ type: Number ,
36+ default: 0
37+ }
38+ },
3039 created () {
3140 window .addEventListener (' keyup' , ({key}) => this .changePageWithKeyBoard (key))
3241 },
42+ data () {
43+ return {
44+ currentPage: 1
45+ }
46+ },
3347 computed: {
3448 items: DatasourceUtils .gettingItems ,
3549 paginationItems () {
3650 return this .items .map ((item , index ) => {
37- return < li class = {{active: (this .pages . current_page === item)}}>
51+ return < li class = {{active: (this .currentPage === item)}}>
3852 < a href= " #" on- click= {(e ) => this .change (e, item)}> {item}< / a>
3953 < / li>
4054 })
55+ },
56+ lastPage () {
57+ if (this .total === 0 ) return 1
58+ return parseInt (((this .total - 1 ) / this .perPage ) + 1 )
4159 }
4260 },
4361 methods: {
4462 firstPage (e ) {
4563 e .preventDefault ()
46- if (this .pages . current_page !== 1 ) {
64+ if (this .currentPage !== 1 ) {
4765 this .change (e, 1 )
4866 }
4967 },
5068 previous (e ) {
5169 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 )
5472 }
5573 },
5674 change (e , page ) {
5775 e .preventDefault ()
76+ this .currentPage = page
5877 EventBus .$emit (' pagination-change' , page)
5978 },
6079 next (e ) {
6180 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 )
6483 }
6584 },
66- lastPage (e , page ) {
85+ goTolastPage (e , page ) {
6786 e .preventDefault ()
68- if (this .pages . current_page !== this .pages . last_page ) {
87+ if (this .currentPage !== this .lastPage ) {
6988 this .change (e, page)
7089 }
7190 },
0 commit comments