fix: wip pagination

This commit is contained in:
kmacoders 2021-07-06 17:59:24 +07:00
parent c2ba6cf36f
commit 0bc5deb958
4 changed files with 67 additions and 5 deletions

View File

@ -0,0 +1,49 @@
<template>
<nav class="pagination is-rounded" role="navigation" aria-label="pagination">
<a class="pagination-previous">Previous</a>
<a class="pagination-next">Next page</a>
<ul class="pagination-list">
<li>
Page {{ currentPage }} / {{ totalPage }}
</li>
</ul>
</nav>
</template>
<script>
import { Vue, Component, Prop } from 'nuxt-property-decorator'
@Component
export default class Pagination extends Vue {
@Prop({ type: Number }) total
@Prop({ type: Number }) perPage
get totalPage () {
return Math.ceil(this.total / this.perPage)
}
get currentPage () {
return Number(this.$route.query.page) || 1
}
get nextPage () {
return (this.currentPage <= this.totalPage) ? this.currentPage + 1 : this.currentPage
}
get prevPage () {
return (this.currentPage >= 1) ? this.currentPage - 1 : this.currentPage
}
get isFirstPage () {
return this.currentPage === 1
}
get isLastPage () {
return this.currentPage === this.totalPage
}
mounted () {
console.log('Total page: ' + this.totalPage)
console.log('Current page: ' + this.currentPage)
}
}
</script>

View File

@ -24,7 +24,7 @@
</p>
<br>
<NuxtLink :to="{name: 'blog-slug', params: { slug: firstBlog.slug }}" class="button is-primary">
Read More
Đọc thêm
</NuxtLink>
</div>
</div>

View File

@ -26,10 +26,10 @@
</p>
<br>
<NuxtLink
:to="blog.path"
:to="{ name: 'blog-slug', params: { slug: blog.slug }}"
class="button is-primary"
>
Read More
Đọc thêm
</NuxtLink>
</div>
</article>

View File

@ -8,6 +8,14 @@
<ListBlog :list-blogs="paginatedArticles" />
</div>
</div>
<div class="columns">
<div class="column is-10 is-offset-1">
<Pagination
:total="allArticles.length"
:per-page="perPage"
/>
</div>
</div>
</div>
</section>
</template>
@ -24,12 +32,13 @@ import ListBlog from '@/components/organisms/ListBlog.vue'
ListBlog
},
async asyncData ({ $content, params, error }) {
const perPage = 8
const content = await getContent($content, params, error, 'blog')
console.log(content)
return {
allArticles: content.allArticles,
paginatedArticles: content.paginatedArticles
paginatedArticles: content.paginatedArticles,
perPage
}
},
head () {
@ -65,6 +74,10 @@ export default class PageBlog extends Vue {
padding: 1.5rem;
}
.blog-posts nav {
padding: 1.5rem;
}
.blog-posts .post img {
border-radius: 6px;
}