Created
September 6, 2018 21:20
-
-
Save rubenestevao/b974d3eed8943838b0f0c69ef8243982 to your computer and use it in GitHub Desktop.
This file contains 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
<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