Skip to content

Commit

Permalink
fix(blog): update blog list page on load
Browse files Browse the repository at this point in the history
  • Loading branch information
janfrl committed Mar 23, 2024
1 parent ac90ff8 commit f6c3b1a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions components/content/BlogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ import type { BlogArticle } from '~/types'
const appConfig = useAppConfig()
const route = useRoute()
const page = ref(Math.max(Number.parseInt(route.query.page as string) || 1, 1))
const page = ref(1)
const active = useState()
const { data: articles } = useFetch<BlogArticle[]>('/api/blog.json', {
default: () => [],
})
const pageArticles = computed(() => {
const start = (page.value - 1) * 12
const end = start + 12
return articles.value?.slice(start, end)
})
watchEffect(() => {
page.value = Math.max(Number.parseInt(route.query.page as string) || 1, 1)
})
watch(page, () => {
navigateTo({ query: { page: page.value > 1 ? page.value : undefined } })
navigateTo({ query: { ...route.query, page: page.value > 1 ? page.value : undefined } })
})
const pageArticles = computed(() => {
const start = (page.value - 1) * 12
const end = start + 12
return articles.value?.slice(start, end)
})
updatePageFromQuery()
function updatePageFromQuery() {
page.value = Math.max(Number.parseInt(route.query.page as string) || 1, 1)
}
function getBadgeProps(badge: keyof typeof appConfig.app.blog.badges | Badge) {
return defu(badge, appConfig.app.blog.badges[badge as keyof typeof appConfig.app.blog.badges] as Badge)
Expand Down

0 comments on commit f6c3b1a

Please sign in to comment.