Explorar o código

Merge pull request #963 from furybean/pagination-bug

Pagination: fix current-change emit too many.
杨奕 %!s(int64=8) %!d(string=hai) anos
pai
achega
2ff91352be

+ 1 - 1
examples/docs/zh-CN/pagination.md

@@ -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] |

+ 13 - 5
packages/pagination/src/pagination.js

@@ -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;
         }
       },
@@ -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() {
@@ -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);
       }
     },

+ 2 - 2
test/unit/specs/pagination.spec.js

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