Last active
January 8, 2018 03:39
-
-
Save wisetc/d71015de3aff575bdcf34a0986423e6a to your computer and use it in GitHub Desktop.
easy pagination mixin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| data() { | |
| return { | |
| pagination: { | |
| currentPage: 1, | |
| pageSizes: [5, 10, 50, 100], | |
| pageSize: 10, | |
| total: null, | |
| layout: "sizes, prev, pager, next" | |
| }, | |
| } | |
| }, | |
| computed: { | |
| _pagination() { | |
| return { | |
| pageIndex: this.pagination.currentPage, | |
| pageSize: this.pagination.pageSize | |
| } | |
| } | |
| }, | |
| methods: { | |
| loadData() {}, // user implement | |
| handleSizeChange(val) { | |
| this.pagination.pageSize = val | |
| this.loadData() | |
| }, | |
| handleCurrentChange(val) { | |
| this.pagination.currentPage = val | |
| this.loadData() | |
| }, | |
| computeRowIndex(index) { | |
| return (this.pagination.currentPage - 1) * this.pagination.pageSize + index + 1 | |
| }, | |
| paginationCallback(total, length) { | |
| this.pagination.total = total | |
| // stupid search pagination | |
| if (!length && this.pagination.currentPage > 1) { | |
| this.pagination.currentPage = 1 | |
| return this.loadData() | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment