From 1ac9c76c3e9c14361170cb16ff19cb04ac48636f Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Sun, 28 Sep 2025 16:40:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(SSR):=20=E4=B8=BA=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=A1=B5=E5=90=AF=E7=94=A8SSR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pages/search.vue | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/pages/search.vue b/app/pages/search.vue index 895d644..9f5f16f 100644 --- a/app/pages/search.vue +++ b/app/pages/search.vue @@ -101,12 +101,24 @@ const localePath = useLocalePath(); // 搜索相关 - const loading = ref(true); const { search } = useMeilisearch(); const keyword = ref(''); const activeRequestId = ref(0); - const sections = ref([]); + const { + data: sections, + pending: loading, + error, + refresh, + } = await useAsyncData( + () => `search-${route.query.query ?? ''}`, + async () => { + const q = String(route.query.query ?? '').trim(); + if (!q) return []; + return await search(q, { limit: 12 }); + } + ); + // 本地化+空Section过滤 const filteredSections = computed(() => sections.value @@ -137,7 +149,7 @@ return map; }); - // 分类控制 + // 分页控制 const currentPage = ref(1); const hasResults = computed(() => @@ -165,7 +177,6 @@ return; } - loading.value = true; try { const results = await search(trimmed, { limit: 12 }); if (requestId === activeRequestId.value) { @@ -178,10 +189,6 @@ if (requestId === activeRequestId.value) { sections.value = []; } - } finally { - if (requestId === activeRequestId.value) { - loading.value = false; - } } }; @@ -204,12 +211,8 @@ ); onMounted(() => { - if (typeof route.query.query === 'string' && route.query.query.trim()) { + if (typeof route.query.query === 'string' && route.query.query.trim()) keyword.value = route.query.query; - performSearch(route.query.query); - } else { - loading.value = false; - } }); useHead(() => ({