mirror of https://github.com/ElemeFE/element
Pagination: handle NaN on props (#10623)
* Pagination: handle pageSize NaN * Pagination: handle currentPage NaNpull/10628/head
parent
6f4f57172b
commit
79325390e2
|
@ -375,27 +375,30 @@ export default {
|
||||||
pageSize: {
|
pageSize: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
handler(val) {
|
handler(val) {
|
||||||
this.internalPageSize = val;
|
this.internalPageSize = isNaN(val) ? 10 : val;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
internalCurrentPage(newVal, oldVal) {
|
internalCurrentPage: {
|
||||||
newVal = parseInt(newVal, 10);
|
immediate: true,
|
||||||
|
handler(newVal, oldVal) {
|
||||||
|
newVal = parseInt(newVal, 10);
|
||||||
|
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (isNaN(newVal)) {
|
if (isNaN(newVal)) {
|
||||||
newVal = oldVal || 1;
|
newVal = oldVal || 1;
|
||||||
} else {
|
} else {
|
||||||
newVal = this.getValidCurrentPage(newVal);
|
newVal = this.getValidCurrentPage(newVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newVal !== undefined) {
|
if (newVal !== undefined) {
|
||||||
this.internalCurrentPage = newVal;
|
this.internalCurrentPage = newVal;
|
||||||
if (oldVal !== newVal) {
|
if (oldVal !== newVal) {
|
||||||
|
this.$emit('update:currentPage', newVal);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.$emit('update:currentPage', newVal);
|
this.$emit('update:currentPage', newVal);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.$emit('update:currentPage', newVal);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,16 @@ describe('Pagination', () => {
|
||||||
expect(vm.$el.querySelectorAll('li.number')).to.length(4);
|
expect(vm.$el.querySelectorAll('li.number')).to.length(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('pageSize: NaN', () => {
|
||||||
|
vm = createTest(Pagination, {
|
||||||
|
pageSize: NaN,
|
||||||
|
total: 100
|
||||||
|
});
|
||||||
|
|
||||||
|
const pagers = vm.$el.querySelectorAll('li.number');
|
||||||
|
expect(pagers).to.length(7);
|
||||||
|
});
|
||||||
|
|
||||||
it('pageCount', () => {
|
it('pageCount', () => {
|
||||||
const vm = createTest(Pagination, {
|
const vm = createTest(Pagination, {
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
|
@ -119,6 +129,17 @@ describe('Pagination', () => {
|
||||||
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('3');
|
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('3');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('currentPage: NaN', () => {
|
||||||
|
vm = createTest(Pagination, {
|
||||||
|
pageSize: 20,
|
||||||
|
total: 200,
|
||||||
|
currentPage: NaN
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('1');
|
||||||
|
expect(vm.$el.querySelectorAll('li.number')).to.length(7);
|
||||||
|
});
|
||||||
|
|
||||||
it('set currentPage & total', (done) => {
|
it('set currentPage & total', (done) => {
|
||||||
vm = createVue({
|
vm = createVue({
|
||||||
template: `
|
template: `
|
||||||
|
|
Loading…
Reference in New Issue