diff --git a/components/article/Category.vue b/components/article/Category.vue index 20019aa..ba30fe2 100644 --- a/components/article/Category.vue +++ b/components/article/Category.vue @@ -9,9 +9,11 @@ const props = defineProps<{ index: number }>() -const { data: articleData } = await useAsyncData(`articles-by-category-${props.category.name}`, () => $fetch('/api/articles/list', { +const { data } = await useFetch('/api/articles/list', { query: { category: props.category.name, page: 1, pageSize: 6 }, -})) +}) + +const articleData = computed(() => data.value ? data.value.payload : []) const isFlipped = ref(false) diff --git a/components/article/Main.vue b/components/article/Main.vue index f1d8a3c..ad3b726 100644 --- a/components/article/Main.vue +++ b/components/article/Main.vue @@ -44,9 +44,19 @@ const displayCols = computed(() => { const page = ref(Number(route.query.page) || 1) const pageSize = ref(6) -const { data: total } = await useAsyncData(`article-count-${props.type}`, () => $fetch('/api/articles/count', { query: whereObj.value })) +const { data: fetchedTotal } = await useAsyncData(`articles-count-${props.type}`, () => $fetch('/api/articles/count', { + query: whereObj.value, +}), { watch: [whereObj] }) +const total = computed(() => fetchedTotal.value ? fetchedTotal.value.payload ?? 0 : 0) -const { data: articleData } = await useAsyncData(`articles-by-page-${props.type}`, () => $fetch('/api/articles/list', { query: { page: page.value, pageSize: pageSize.value, ...whereObj.value } }), { watch: [query] }) +const { data: fetchedArticleData } = await useAsyncData(`articles-list-${props.type}`, () => $fetch('/api/articles/list', { + query: { + page: page.value, + pageSize: pageSize.value, + ...whereObj.value, + }, +}), { watch: [page, pageSize, whereObj] }) +const articleData = computed(() => fetchedArticleData.value ? fetchedArticleData.value.payload ?? [] : []) watch(page, async (newPage) => { router.replace({ query: { ...route.query, page: newPage.toString() } }) @@ -60,7 +70,7 @@ watch(() => route.query.page, (pageQuery) => { }) const articleCards = computed(() => - articleData.value?.map((article) => { + articleData.value.map((article) => { return { to: article.to, title: article.title, @@ -71,7 +81,7 @@ const articleCards = computed(() => editedAt: article.editedAt, wordCount: article.wordCount, } - }) || [], + }), ) @@ -83,7 +93,7 @@ const articleCards = computed(() =>
- +
diff --git a/components/main/Body.vue b/components/main/Body.vue index c0bd097..2c65548 100644 --- a/components/main/Body.vue +++ b/components/main/Body.vue @@ -1,10 +1,11 @@ diff --git a/components/main/Header/index.vue b/components/main/Header/index.vue index d7cc380..16e08d9 100644 --- a/components/main/Header/index.vue +++ b/components/main/Header/index.vue @@ -1,7 +1,10 @@