Created
July 4, 2018 12:24
-
-
Save em7v/ce02368485be6dcdcc9201a369fef054 to your computer and use it in GitHub Desktop.
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
<template> | |
<div class="mt-4" v-if="pagination.total_pages > 1"> | |
<nav aria-label="Page navigation example"> | |
<ul class="pagination"> | |
<li class="page-item" | |
@click="onPaginate(pagination.current_page - 1)" | |
> | |
<a class="page-link" href="#" aria-label="Previous" | |
:class="{'disabled-pagination-link': pagination.current_page === 1}" | |
> | |
<span aria-hidden="true">«</span> | |
<span class="sr-only">Previous</span> | |
</a> | |
</li> | |
<li class="page-item" | |
v-for="page in totalPage" | |
:class="{active: pagination.current_page === page}" | |
:disabled="pagination.current_page === page" | |
> | |
<a class="page-link" | |
href="#" | |
@click="onPaginate(page)" | |
:class="{'disabled-pagination-link': pagination.current_page === page}" | |
>{{ page }}</a> | |
</li> | |
<li class="page-item" | |
:class="{'disabled-pagination-link': pagination.current_page === pagination.total_pages}" | |
> | |
<a class="page-link" | |
href="#" | |
aria-label="Next" | |
@click="onPaginate(pagination.current_page + 1)" | |
> | |
<span aria-hidden="true">»</span> | |
<span class="sr-only">Next</span> | |
</a> | |
</li> | |
</ul> | |
</nav> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'pagination', | |
props: { | |
pagination: { | |
type: Object, | |
required: true, | |
} | |
}, | |
data () { | |
return { | |
pages: [], | |
} | |
}, | |
mounted () { | |
}, | |
computed: { | |
totalPage () { | |
let pages = [] | |
for (let i = 1; i <= this.pagination.total_pages; i++) { | |
pages.push(i) | |
} | |
return pages | |
} | |
}, | |
methods: { | |
onPaginate (page) { | |
this.$emit('paginate', page) | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
.disabled-pagination-link { | |
pointer-events: none; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment