regex for number check
This commit is contained in:
parent
4dd82e1d49
commit
39a8f1aaf4
2 changed files with 12 additions and 7 deletions
|
@ -9,9 +9,14 @@
|
|||
'pagenum',
|
||||
],
|
||||
methods: {
|
||||
pagenumberstatus(n) {
|
||||
if (n - 1 === +this.pagenum) return 'active';
|
||||
return '';
|
||||
pagestatus(n) {
|
||||
if (n - 1 === +this.pagenum) return true;
|
||||
return false;
|
||||
},
|
||||
prevstatus(index) {
|
||||
if (index > 0) return false;
|
||||
if (+this.pagenum < 2) return true;
|
||||
return false;
|
||||
},
|
||||
createSection(n) { return Array.from(Array(n)).map((e, i) => i); },
|
||||
},
|
||||
|
@ -22,7 +27,7 @@
|
|||
const pages = this.createSection(+this.last + 1);
|
||||
pages.shift();
|
||||
|
||||
if (+this.pagenum !== 1) items.push({ text: 'Prev' });
|
||||
items.push({ text: 'Prev', class: this.prevstatus() });
|
||||
|
||||
pages.forEach(i => items.push({ text: i }));
|
||||
|
||||
|
@ -34,8 +39,8 @@
|
|||
},
|
||||
template: `
|
||||
<div class="gl-pagination">
|
||||
<ul class="pagination clearfix" v-for='(item, index) in getItems'>
|
||||
<li :class='pagenumberstatus(index + 1)'>
|
||||
<ul class="pagination clearfix" v-for='(item, i) in getItems'>
|
||||
<li :class="{active: pagestatus(i + 1), disabled: prevstatus(i)}">
|
||||
<span @click='changepage($event, last)'>{{item.text}}</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
},
|
||||
changepage(event, last) {
|
||||
const text = event.target.innerText;
|
||||
if (typeof text === 'number') this.pagenum = +text;
|
||||
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
|
||||
if (text === 'Last »') this.pagenum = last;
|
||||
if (text === 'Next') this.pagenum = +this.pagenum + 1;
|
||||
if (text === 'Prev') this.pagenum = +this.pagenum - 1;
|
||||
|
|
Loading…
Reference in a new issue