-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Pagination.vue fix from dev branch
- Loading branch information
1 parent
ad4d491
commit 611425b
Showing
1 changed file
with
70 additions
and
72 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,87 @@ | ||
<template> | ||
|
||
<nav class="codeweek-pagination" role="navigation" aria-label="pagination"> | ||
<ul> | ||
<li> | ||
<a class="back" | ||
@click.prevent="changePage(pagination.current_page - 1)" | ||
:disabled="pagination.current_page <= 1"> | ||
{{$t('pagination.previous')}} | ||
</a> | ||
</li> | ||
<li v-for="page in pages"> | ||
<a v-if="pagination.current_page != page" | ||
class="page" | ||
@click.prevent="changePage(page)"> | ||
{{ page }} | ||
</a> | ||
<a v-else | ||
class="page current"> | ||
{{ page }} | ||
</a> | ||
</li> | ||
<li> | ||
<a class="next" | ||
@click.prevent="changePage(pagination.current_page + 1)" | ||
:disabled="pagination.current_page >= pagination.last_page"> | ||
{{$t('pagination.next')}} | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
|
||
<nav class="codeweek-pagination" role="navigation" aria-label="pagination"> | ||
<ul> | ||
<li> | ||
<a | ||
class="back" | ||
@click.prevent="changePage(pagination.current_page - 1)" | ||
:disabled="pagination.current_page <= 1" | ||
> | ||
{{ $t('pagination.previous') }} | ||
</a> | ||
</li> | ||
<li v-for="page in pages"> | ||
<a | ||
v-if="pagination.current_page != page" | ||
class="page" | ||
@click.prevent="changePage(page)" | ||
> | ||
{{ page }} | ||
</a> | ||
<a v-else class="page current"> | ||
{{ page }} | ||
</a> | ||
</li> | ||
<li> | ||
<a | ||
class="next" | ||
@click.prevent="changePage(pagination.current_page + 1)" | ||
:disabled="pagination.current_page >= pagination.last_page" | ||
> | ||
{{ $t('pagination.next') }} | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
</template> | ||
|
||
<style> | ||
.pagination { | ||
margin-top: 40px; | ||
} | ||
.pagination { | ||
margin-top: 40px; | ||
} | ||
</style> | ||
|
||
<script> | ||
export default { | ||
props: ['pagination', 'offset'], | ||
methods: { | ||
isCurrentPage(page) { | ||
return this.pagination.current_page === page; | ||
}, | ||
export default { | ||
props: ['pagination', 'offset'], | ||
changePage(page) { | ||
if (page === 0 || (page > this.pagination.last_page)){ | ||
return; | ||
} | ||
methods: { | ||
isCurrentPage(page) { | ||
return this.pagination.current_page === page; | ||
}, | ||
if (page > this.pagination.last_page) { | ||
page = this.pagination.last_page; | ||
} | ||
this.pagination.current_page = page; | ||
this.$dispatch('paginate'); | ||
} | ||
}, | ||
changePage(page) { | ||
if (page < 1 || page > this.pagination.last_page) { | ||
return; | ||
} | ||
this.pagination.current_page = page; | ||
this.$emit('paginate', page); // Emit the event with the new page number | ||
} | ||
}, | ||
computed: { | ||
pages() { | ||
let pages = []; | ||
computed: { | ||
pages() { | ||
let pages = []; | ||
let from = this.pagination.current_page - Math.floor(this.offset / 2); | ||
let from = this.pagination.current_page - Math.floor(this.offset / 2); | ||
if (from < 1) { | ||
from = 1; | ||
} | ||
if (from < 1) { | ||
from = 1; | ||
} | ||
let to = from + this.offset - 1; | ||
let to = from + this.offset - 1; | ||
if (to > this.pagination.last_page) { | ||
to = this.pagination.last_page; | ||
} | ||
if (to > this.pagination.last_page) { | ||
to = this.pagination.last_page; | ||
} | ||
while (from <= to) { | ||
pages.push(from); | ||
from++; | ||
} | ||
while (from <= to) { | ||
pages.push(from); | ||
from++; | ||
} | ||
return pages; | ||
} | ||
} | ||
return pages; | ||
} | ||
</script> | ||
} | ||
}; | ||
</script> |