Skip to content

Commit

Permalink
Merge pull request ElemeFE#963 from furybean/pagination-bug
Browse files Browse the repository at this point in the history
Pagination: fix current-change emit too many.
  • Loading branch information
Leopoldthecoder authored Nov 10, 2016
2 parents 4ccb8ea + 28958fa commit 2ff9135
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/docs/zh-CN/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
| small | 是否使用小型分页样式 | Boolean || false |
| page-size | 每页显示条目个数 | Number || 10 |
| total | 总条目数 | Number || - |
| page-count | 总页数,total 和 page-count 设置任意一个就可以达到显示页码的功能如果要支持 page-sizes 的更改,则需要使用 total 属性;如果要支持 page-sizes 的更改,则需要使用 total 属性 | Number || - |
| page-count | 总页数,total 和 page-count 设置任意一个就可以达到显示页码的功能;如果要支持 page-sizes 的更改,则需要使用 total 属性 | Number || - |
| current-page | 当前页数 | Number || 1 |
| layout | 组件布局,子组件名用逗号分隔| String | `sizes`, `prev`, `pager`, `next`, `jumper`, `->`, `total` | 'prev, pager, next, jumper, ->, total' |
| page-sizes | 每页显示个数选择器的选项设置 | Number[] || [10, 20, 30, 40, 50, 100] |
Expand Down
18 changes: 13 additions & 5 deletions packages/pagination/src/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ export default {
},

handleChange({ target }) {
const oldPage = this.$parent.internalCurrentPage;
this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(target.value);
this.$parent.$emit('current-change', this.$parent.internalCurrentPage);
if (oldPage !== this.$parent.internalCurrentPage) {
this.$parent.$emit('current-change', this.$parent.internalCurrentPage);
}
this.oldValue = null;
}
},
Expand Down Expand Up @@ -225,8 +228,11 @@ export default {
},

handleCurrentChange(val) {
const oldPage = this.internalCurrentPage;
this.internalCurrentPage = this.getValidCurrentPage(val);
this.$emit('current-change', this.internalCurrentPage);
if (oldPage !== this.internalCurrentPage) {
this.$emit('current-change', this.internalCurrentPage);
}
},

prev() {
Expand Down Expand Up @@ -289,11 +295,13 @@ export default {
watch: {
internalPageCount(newVal) {
/* istanbul ignore if */
if (newVal > 0 && this.internalCurrentPage === 0) {
const oldPage = this.internalCurrentPage;
if (newVal > 0 && oldPage === 0) {
this.internalCurrentPage = 1;
this.$emit('current-change', 1);
} else if (this.internalCurrentPage > newVal) {
} else if (oldPage > newVal) {
this.internalCurrentPage = newVal === 0 ? 1 : newVal;
}
if (oldPage !== this.internalCurrentPage) {
this.$emit('current-change', this.internalCurrentPage);
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/specs/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('Pagination', () => {
},

data() {
return { page: 0 };
return { page: 1 };
}
}, true);
const input = vm.$el.querySelector('.el-pagination__jump input');
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Pagination', () => {
},

data() {
return { page: 0 };
return { page: 1 };
}
});
const input = vm.$el.querySelector('.el-pagination__jump input');
Expand Down

0 comments on commit 2ff9135

Please sign in to comment.