2
2
<div class =" vue-tiny-pagination" >
3
3
<ul class =" tiny-pagination" :class =" customClass" >
4
4
<li class =" page-item" :class =" classFirstPage" >
5
- <a class =" btn-prev-page" href =" #" @click.prevent =" lastPage" >{{translation.prev}}</a >
5
+ <a class =" btn-prev-page" href =" #" @click.prevent =" lastPage" >{{ translation.prev }}</a >
6
6
</li >
7
7
<li class =" page-item" >
8
- <span >{{titlePage}}</span >
8
+ <span >{{ titlePage }}</span >
9
9
</li >
10
10
<li class =" page-item" :class =" classLastPage" >
11
- <a class =" btn-next-page" href =" #" @click.prevent =" nextPage" >{{translation.next}}</a >
11
+ <a class =" btn-next-page" href =" #" @click.prevent =" nextPage" >{{ translation.next }}</a >
12
12
</li >
13
13
<li v-if =" showLimit" class =" page-item" >
14
- <select class =" tiny-form-select" v-model = " currentLimit " @change =" onLimitChange" >
14
+ <select v-model = " currentLimit " class =" tiny-form-select" @change =" onLimitChange" >
15
15
<option
16
16
v-for =" (limit, index) in limits"
17
- :value = " limit "
18
- :key = " index " >{{limit}}/{{translation.title}}</option >
17
+ :key = " index "
18
+ :value = " limit " >{{ limit }}/{{ translation.title }}</option >
19
19
</select >
20
20
</li >
21
21
</ul >
22
22
</div >
23
23
</template >
24
-
25
24
<script >
26
25
export default {
27
26
name: ' TinyPagination' ,
@@ -40,19 +39,20 @@ export default {
40
39
},
41
40
customClass: {
42
41
type: String ,
42
+ default: ' ' ,
43
43
},
44
44
limits: {
45
45
type: Array ,
46
- default () {
46
+ default () {
47
47
return [10 , 15 , 20 , 50 , 100 ];
48
48
},
49
49
},
50
50
showLimit: {
51
51
type: Boolean ,
52
52
default: true ,
53
- }
53
+ },
54
54
},
55
- data () {
55
+ data () {
56
56
return {
57
57
version: ' 0.3.1' ,
58
58
currentPage: 1 ,
@@ -67,73 +67,73 @@ export default {
67
67
prev: ' Anterior' ,
68
68
title: ' Página' ,
69
69
next: ' Siguiente' ,
70
- }
70
+ },
71
71
},
72
72
availableLanguages: [' en' , ' es' ],
73
73
};
74
74
},
75
- created () {
76
- this .currentPage = this .page
77
- },
78
75
computed: {
79
- translation () {
80
- return (this .availableLanguages .includes (this .lang )) ?
81
- this .translations [this .lang ]
82
- : this .translations [ ' en ' ]
76
+ translation () {
77
+ return (this .availableLanguages .includes (this .lang ))
78
+ ? this .translations [this .lang ]
79
+ : this .translations . en ;
83
80
},
84
- totalPages () {
85
- return Math .ceil (this .total / this .currentLimit )
81
+ totalPages () {
82
+ return Math .ceil (this .total / this .currentLimit );
86
83
},
87
- titlePage () {
88
- return ` ${ this .translation .title } ${ this .currentPage } `
84
+ titlePage () {
85
+ return ` ${ this .translation .title } ${ this .currentPage } ` ;
89
86
},
90
- classFirstPage () {
87
+ classFirstPage () {
91
88
return {
92
89
disabled: (this .currentPage === 1 ),
93
- ' c-not-allowed' : true
94
- }
90
+ ' c-not-allowed' : true ,
91
+ };
95
92
},
96
- classLastPage () {
93
+ classLastPage () {
97
94
return {
98
95
disabled: (this .currentPage === this .totalPages ),
99
- ' c-not-allowed' : true
100
- }
101
- }
96
+ ' c-not-allowed' : true ,
97
+ };
98
+ },
99
+ },
100
+ watch: {
101
+ currentPage (value ) {
102
+ this .$emit (' tiny:change-page' , {
103
+ page: value,
104
+ });
105
+ },
106
+ currentLimit (value ) {
107
+ this .$emit (' tiny:change-limit' , {
108
+ limit: value,
109
+ });
110
+ },
111
+ },
112
+ created () {
113
+ this .currentPage = this .page ;
102
114
},
103
115
methods: {
104
- nextPage () {
116
+ nextPage () {
105
117
if (this .currentPage !== this .totalPages ) {
106
- this .currentPage += 1
118
+ this .currentPage += 1 ;
107
119
}
108
120
},
109
- lastPage () {
121
+ lastPage () {
110
122
if (this .currentPage > 1 ) {
111
- this .currentPage -= 1
123
+ this .currentPage -= 1 ;
112
124
}
113
125
},
114
- onLimitChange () {
115
- this .currentPage = 1
116
- }
117
- },
118
- watch: {
119
- currentPage (value ) {
120
- this .$emit (' tiny:change-page' , {
121
- page: value
122
- })
126
+ onLimitChange () {
127
+ this .currentPage = 1 ;
123
128
},
124
- currentLimit (value ) {
125
- this .$emit (' tiny:change-limit' , {
126
- limit: value
127
- })
128
- }
129
- }
130
- }
129
+ },
130
+ };
131
131
</script >
132
-
133
132
<style lang="scss">
134
133
// Pagination
134
+ $apple-fonts : -apple-system , system-ui , BlinkMacSystemFont;
135
135
.tiny-pagination {
136
- font-family : - apple-system , system-ui , BlinkMacSystemFont , " Segoe UI" , Roboto, " Helvetica Neue" , sans-serif ;
136
+ font-family : $ apple-fonts , " Segoe UI" , Roboto, " Helvetica Neue" , sans-serif ;
137
137
display : flex ;
138
138
list-style : none ;
139
139
margin : .2rem 0 ;
@@ -218,4 +218,4 @@ export default {
218
218
padding-right : 1.2rem ;
219
219
}
220
220
}
221
- </style >
221
+ </style >
0 commit comments