From 44ceb8ce2bf8dd188ac1e0d84fa0c78d095f55ae Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Wed, 2 Oct 2024 14:57:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A0=E8=BD=BD=E9=AA=A8?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/home/HomeView.vue | 53 ++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/views/home/HomeView.vue b/src/views/home/HomeView.vue index 702b96c..32c4682 100644 --- a/src/views/home/HomeView.vue +++ b/src/views/home/HomeView.vue @@ -7,11 +7,38 @@ import NavBar from "@/components/nav/NavBar.vue"; import IntroCard from "@/components/card/IntroCard.vue"; const recentPosts = ref(null); +const isLoading = ref(true); +const isError = ref(false); + const hasPosts = computed(() => (recentPosts.value ?? []).length > 0); +const postsData = computed(() => { + if (!recentPosts.value) return []; + if (recentPosts.value.length > 4) + return recentPosts.value.slice(0, 4) + return recentPosts.value +}) + +const reloadPosts = async () => { + try { + isLoading.value = true + const postData = await getBlogRecentPost(); + recentPosts.value = postData.data.dataSet + isLoading.value = false + } catch (e) { + isLoading.value = false + isError.value = true + } +} onMounted(async () => { - const postData = await getBlogRecentPost(); - recentPosts.value = postData.data.dataSet + try { + const postData = await getBlogRecentPost(); + recentPosts.value = postData.data.dataSet + isLoading.value = false + } catch (e) { + isLoading.value = false + isError.value = true + } }) @@ -36,10 +63,24 @@ onMounted(async () => { -
- 最近没有动态 -
- +
+
+
+
+
+
+
+
+ + 载入错误 +
+
+ 最近没有动态 +
+ +
+