Created
March 24, 2019 19:10
-
-
Save Tenderfeel/dda6e29c679aee700db6489efc266839 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
<template> | |
<div class="pagination"> | |
<a | |
:href="`?page=${prevPage}`" | |
class="prev" | |
v-if="currentPage > 1" | |
@click.prevent="onPrev" | |
>< 前へ</a> | |
<div class="total">ページ {{currentPage}}/{{totalPage}}</div> | |
<a | |
:href="`?page=${nextPage}`" | |
class="next" | |
v-if="currentPage < totalPage" | |
@click.prevent="onNext" | |
>次へ ></a> | |
</div> | |
</template> | |
<script> | |
export default { | |
props: { | |
page: { | |
type: Number, | |
required: true | |
}, | |
totalPage: { | |
type: Number, | |
required: true | |
} | |
}, | |
data() { | |
return { | |
currentPage: this.page | |
}; | |
}, | |
computed: { | |
prevPage() { | |
return Math.max(this.currentPage - 1, 1); | |
}, | |
nextPage() { | |
return Math.min(this.currentPage + 1, this.totalPage); | |
} | |
}, | |
methods: { | |
onPrev() { | |
this.currentPage = this.prevPage; | |
this.$emit("change", this.currentPage); | |
}, | |
onNext() { | |
this.currentPage = this.nextPage; | |
this.$emit("change", this.currentPage); | |
} | |
} | |
}; | |
</script> | |
<style scoped> | |
.pagination { | |
text-align: center; | |
} | |
.pagination * { | |
display: inline; | |
} | |
a { | |
border: 0; | |
background: none; | |
font-size: initial; | |
cursor: pointer; | |
margin: 0 1rem; | |
} | |
</style> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment