feat(SSR): 为站点添加SSR机制 #38
@ -101,12 +101,24 @@
|
||||
const localePath = useLocalePath();
|
||||
|
||||
// 搜索相关
|
||||
const loading = ref(true);
|
||||
const { search } = useMeilisearch();
|
||||
const keyword = ref('');
|
||||
const activeRequestId = ref(0);
|
||||
|
||||
const sections = ref<SearchSection[]>([]);
|
||||
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(() => ({
|
||||
|
||||
Reference in New Issue
Block a user