From da190da59aa9e0fb151e379200d85bc9adf2549f Mon Sep 17 00:00:00 2001 From: linhaojun Date: Tue, 27 Sep 2022 22:24:52 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=A7=84=E8=8C=83Home.vue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aurora-vue/aurora-blog/src/views/Home.vue | 54 ++++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/aurora-vue/aurora-blog/src/views/Home.vue b/aurora-vue/aurora-blog/src/views/Home.vue index 408d714..9e8482d 100644 --- a/aurora-vue/aurora-blog/src/views/Home.vue +++ b/aurora-vue/aurora-blog/src/views/Home.vue @@ -135,6 +135,8 @@ export default defineComponent({ articleOffset.value = articleListEl && articleListEl instanceof HTMLElement ? articleListEl.offsetTop + 120 : 0 } + onMounted(fetchData) + const fetchTopAndFeatured = () => { api.getTopAndFeaturedArticles().then(({ data }) => { data.data.topArticle.articleContent = md @@ -154,13 +156,6 @@ export default defineComponent({ }) } - const fetchCategories = () => { - categoryStore.categories = [] - api.getAllCategories().then(({ data }) => { - categoryStore.categories.push(...data.data) - }) - } - const fetchArticles = () => { reactiveData.haveArticles = false api @@ -184,25 +179,6 @@ export default defineComponent({ }) } - onMounted(fetchData) - - const expandHandler = () => { - expanderClass.value.expanded = !expanderClass.value.expanded - tabClass.value['expanded-tab'] = !tabClass.value['expanded-tab'] - } - - const handleTabChange = (categoryId: any) => { - pagination.current = 1 - activeTab.value = categoryId - backToPageTop() - if (categoryId !== 0) { - nowCategoryId = categoryId - fetchArticlesByCategoryId(categoryId) - } else { - nowCategoryId = categoryId - fetchArticles() - } - } const fetchArticlesByCategoryId = (categoryId: any) => { reactiveData.haveArticles = false api @@ -224,6 +200,32 @@ export default defineComponent({ reactiveData.haveArticles = true }) } + + const fetchCategories = () => { + categoryStore.categories = [] + api.getAllCategories().then(({ data }) => { + categoryStore.categories.push(...data.data) + }) + } + + const expandHandler = () => { + expanderClass.value.expanded = !expanderClass.value.expanded + tabClass.value['expanded-tab'] = !tabClass.value['expanded-tab'] + } + + const handleTabChange = (categoryId: any) => { + pagination.current = 1 + activeTab.value = categoryId + backToPageTop() + if (categoryId !== 0) { + nowCategoryId = categoryId + fetchArticlesByCategoryId(categoryId) + } else { + nowCategoryId = categoryId + fetchArticles() + } + } + const backToPageTop = () => { window.scrollTo({ top: articleOffset.value