Skip to content

Instantly share code, notes, and snippets.

@rubenestevao
Created September 6, 2018 21:20
Show Gist options
  • Save rubenestevao/b974d3eed8943838b0f0c69ef8243982 to your computer and use it in GitHub Desktop.
Save rubenestevao/b974d3eed8943838b0f0c69ef8243982 to your computer and use it in GitHub Desktop.
<script>
const isNaN = Number.isNaN || window.isNaN;
export default {
props: ['pagination'],
data() {
return {
page: this.pagination.current_page,
};
},
computed: {
location() {
let size = this.pagination.first_page_url.lastIndexOf('=') + 1;
return this.pagination.first_page_url.slice(0, size) + this.page;
}
},
methods: {
changePage(e) {
let page = parseInt(e.target.value);
if (isNaN(page) || page < 1 || page > this.pagination.last_page) {
e.target.value = this.page;
return;
}
this.page = page;
window.location.assign(this.location);
}
},
render() {
return this.$scopedSlots.default({
changePage: this.changePage,
page: this.page,
});
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment