@@ -5,53 +5,73 @@ export default {
5
5
props: {
6
6
data: {
7
7
type: Object ,
8
- default : () => {}
8
+ default : () => {},
9
9
},
10
10
limit: {
11
11
type: Number ,
12
- default: 0
12
+ default: 0 ,
13
13
},
14
14
keepLength: {
15
15
type: Boolean ,
16
- default: false
16
+ default: false ,
17
17
},
18
18
},
19
19
20
20
computed: {
21
- isApiResource () {
21
+ isApiResource () {
22
22
return !! this .data .meta ;
23
23
},
24
- currentPage () {
25
- return this .isApiResource ? this .data .meta .current_page : this .data .current_page ;
26
- },
27
- firstPageUrl () {
28
- return this .isApiResource ? this .data .links .first : null ;
29
- },
30
- from () {
31
- return this .isApiResource ? this .data .meta .from : this .data .from ;
32
- },
33
- lastPage () {
34
- return this .isApiResource ? this .data .meta .last_page : this .data .last_page ;
35
- },
36
- lastPageUrl () {
37
- return this .isApiResource ? this .data .links .last : null ;
38
- },
39
- nextPageUrl () {
40
- return this .isApiResource ? this .data .links .next : this .data .next_page_url ;
41
- },
42
- perPage () {
43
- return this .isApiResource ? this .data .meta .per_page : this .data .per_page ;
44
- },
45
- prevPageUrl () {
46
- return this .isApiResource ? this .data .links .prev : this .data .prev_page_url ;
47
- },
48
- to () {
49
- return this .isApiResource ? this .data .meta .to : this .data .to ;
50
- },
51
- total () {
52
- return this .isApiResource ? this .data .meta .total : this .data .total ;
53
- },
54
- pageRange () {
24
+ currentPage () {
25
+ return this .isApiResource
26
+ ? this .data .meta .current_page
27
+ : this .data .current_page ?? null ;
28
+ },
29
+ firstPageUrl () {
30
+ return this .isApiResource
31
+ ? this .data .links .first
32
+ : this .data .first_page_url ?? null ;
33
+ },
34
+ from () {
35
+ return this .isApiResource
36
+ ? this .data .meta .from
37
+ : this .data .from ?? null ;
38
+ },
39
+ lastPage () {
40
+ return this .isApiResource
41
+ ? this .data .meta .last_page
42
+ : this .data .last_page ?? null ;
43
+ },
44
+ lastPageUrl () {
45
+ return this .isApiResource
46
+ ? this .data .links .last
47
+ : this .data .last_page_url ?? null ;
48
+ },
49
+ nextPageUrl () {
50
+ return this .isApiResource
51
+ ? this .data .links .next
52
+ : this .data .next_page_url ?? null ;
53
+ },
54
+ perPage () {
55
+ return this .isApiResource
56
+ ? this .data .meta .per_page
57
+ : this .data .per_page ?? null ;
58
+ },
59
+ prevPageUrl () {
60
+ return this .isApiResource
61
+ ? this .data .links .prev
62
+ : this .data .prev_page_url ?? null ;
63
+ },
64
+ to () {
65
+ return this .isApiResource
66
+ ? this .data .meta .to
67
+ : this .data .to ?? null ;
68
+ },
69
+ total () {
70
+ return this .isApiResource
71
+ ? this .data .meta .total
72
+ : this .data .total ?? null ;
73
+ },
74
+ pageRange () {
55
75
if (this .limit === - 1 ) {
56
76
return 0 ;
57
77
}
@@ -67,7 +87,7 @@ export default {
67
87
var left = current - delta;
68
88
var right = current + delta;
69
89
var leftPad = (delta + 2 ) * 2 ;
70
- var rightPad = (( delta + 2 ) * 2 ) - 1 ;
90
+ var rightPad = (delta + 2 ) * 2 - 1 ;
71
91
var range = [];
72
92
var pages = [];
73
93
var l;
@@ -86,7 +106,11 @@ export default {
86
106
range .push (i);
87
107
}
88
108
// Item is after max right padding
89
- else if (size && i > last - rightPad && current > last - rightPad + 2 ) {
109
+ else if (
110
+ size &&
111
+ i > last - rightPad &&
112
+ current > last - rightPad + 2
113
+ ) {
90
114
range .push (i);
91
115
}
92
116
}
@@ -104,26 +128,26 @@ export default {
104
128
});
105
129
106
130
return pages;
107
- }
131
+ },
108
132
},
109
133
110
134
methods: {
111
- previousPage () {
112
- this .selectPage (( this .currentPage - 1 ) );
135
+ previousPage () {
136
+ this .selectPage (this .currentPage - 1 );
113
137
},
114
- nextPage () {
115
- this .selectPage (( this .currentPage + 1 ) );
138
+ nextPage () {
139
+ this .selectPage (this .currentPage + 1 );
116
140
},
117
- selectPage (page ) {
141
+ selectPage (page ) {
118
142
if (page === ' ...' || page === this .currentPage ) {
119
143
return ;
120
144
}
121
145
122
146
this .$emit (' pagination-change-page' , page);
123
- }
147
+ },
124
148
},
125
149
126
- render () {
150
+ render () {
127
151
return this .$slots .default ({
128
152
data: this .data ,
129
153
limit: this .limit ,
@@ -139,27 +163,27 @@ export default {
139
163
prevPageUrl: this .prevPageUrl ,
140
164
to: this .to ,
141
165
total: this .total ,
142
- pageRange: this .pageRange
166
+ pageRange: this .pageRange ,
143
167
},
144
168
prevButtonEvents: {
145
169
click : (e ) => {
146
170
e .preventDefault ();
147
171
this .previousPage ();
148
- }
172
+ },
149
173
},
150
174
nextButtonEvents: {
151
175
click : (e ) => {
152
176
e .preventDefault ();
153
177
this .nextPage ();
154
- }
178
+ },
155
179
},
156
- pageButtonEvents : page => ({
180
+ pageButtonEvents : ( page ) => ({
157
181
click : (e ) => {
158
182
e .preventDefault ();
159
183
this .selectPage (page);
160
- }
161
- })
184
+ },
185
+ }),
162
186
});
163
- }
164
- }
187
+ },
188
+ };
165
189
< / script>
0 commit comments