Skip to content

Commit

Permalink
fix: table pagination trigger multiple change events when `showSizeCh…
Browse files Browse the repository at this point in the history
…anger=true` #228
  • Loading branch information
tangjinzhou committed Oct 23, 2018
1 parent 9638e01 commit 9f70380
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/pagination/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
},
model: {
prop: 'current',
event: 'change',
event: 'change.current',
},
methods: {
renderPagination (contextLocale) {
Expand Down
9 changes: 6 additions & 3 deletions components/vc-pagination/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default {
total: PropTypes.number.def(0),
pageSize: PropTypes.number,
defaultPageSize: PropTypes.number.def(10),
change: PropTypes.func.def(noop),
hideOnSinglePage: PropTypes.bool.def(false),
showSizeChanger: PropTypes.bool.def(false),
showLessItems: PropTypes.bool.def(false),
Expand All @@ -50,7 +49,7 @@ export default {
},
model: {
prop: 'current',
event: 'change',
event: 'change.current',
},
data () {
const hasOnChange = this.onChange !== noop
Expand Down Expand Up @@ -174,6 +173,7 @@ export default {
},
changePageSize (size) {
let current = this.stateCurrent
const preCurrent = current
const newCurrent = this.calculatePage(size)
current = current > newCurrent ? newCurrent : current
// fix the issue:
Expand All @@ -196,7 +196,9 @@ export default {
}
this.$emit('update:pageSize', size)
this.$emit('showSizeChange', current, size)
this.$emit('change', current, size)
if (current !== preCurrent) {
this.$emit('change.current', current, size)
}
},
handleChange (p) {
let page = p
Expand All @@ -213,6 +215,7 @@ export default {
}
// this.$emit('input', page)
this.$emit('change', page, this.statePageSize)
this.$emit('change.current', page, this.statePageSize)
return page
}
return this.stateCurrent
Expand Down

0 comments on commit 9f70380

Please sign in to comment.