From 9f70380bd8536f2b59d6fb32663a0bc6268c0e35 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Tue, 23 Oct 2018 12:49:40 +0800 Subject: [PATCH] fix: table pagination trigger multiple change events when `showSizeChanger=true` #228 --- components/pagination/Pagination.jsx | 2 +- components/vc-pagination/Pagination.jsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/pagination/Pagination.jsx b/components/pagination/Pagination.jsx index e7bd272eb..293a6fee7 100644 --- a/components/pagination/Pagination.jsx +++ b/components/pagination/Pagination.jsx @@ -46,7 +46,7 @@ export default { }, model: { prop: 'current', - event: 'change', + event: 'change.current', }, methods: { renderPagination (contextLocale) { diff --git a/components/vc-pagination/Pagination.jsx b/components/vc-pagination/Pagination.jsx index fbfc0c21c..2d3a272c4 100644 --- a/components/vc-pagination/Pagination.jsx +++ b/components/vc-pagination/Pagination.jsx @@ -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), @@ -50,7 +49,7 @@ export default { }, model: { prop: 'current', - event: 'change', + event: 'change.current', }, data () { const hasOnChange = this.onChange !== noop @@ -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: @@ -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 @@ -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