Skip to content

Instantly share code, notes, and snippets.

@wisetc
Last active January 8, 2018 03:39
Show Gist options
  • Select an option

  • Save wisetc/d71015de3aff575bdcf34a0986423e6a to your computer and use it in GitHub Desktop.

Select an option

Save wisetc/d71015de3aff575bdcf34a0986423e6a to your computer and use it in GitHub Desktop.
easy pagination mixin.
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