feat(SSR): 为搜索页启用SSR
This commit is contained in:
@ -101,12 +101,24 @@
|
|||||||
const localePath = useLocalePath();
|
const localePath = useLocalePath();
|
||||||
|
|
||||||
// 搜索相关
|
// 搜索相关
|
||||||
const loading = ref(true);
|
|
||||||
const { search } = useMeilisearch();
|
const { search } = useMeilisearch();
|
||||||
const keyword = ref('');
|
const keyword = ref('');
|
||||||
const activeRequestId = ref(0);
|
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过滤
|
// 本地化+空Section过滤
|
||||||
const filteredSections = computed(() =>
|
const filteredSections = computed(() =>
|
||||||
sections.value
|
sections.value
|
||||||
@ -137,7 +149,7 @@
|
|||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 分类控制
|
// 分页控制
|
||||||
const currentPage = ref(1);
|
const currentPage = ref(1);
|
||||||
|
|
||||||
const hasResults = computed(() =>
|
const hasResults = computed(() =>
|
||||||
@ -165,7 +177,6 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = true;
|
|
||||||
try {
|
try {
|
||||||
const results = await search(trimmed, { limit: 12 });
|
const results = await search(trimmed, { limit: 12 });
|
||||||
if (requestId === activeRequestId.value) {
|
if (requestId === activeRequestId.value) {
|
||||||
@ -178,10 +189,6 @@
|
|||||||
if (requestId === activeRequestId.value) {
|
if (requestId === activeRequestId.value) {
|
||||||
sections.value = [];
|
sections.value = [];
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (requestId === activeRequestId.value) {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,12 +211,8 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
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;
|
keyword.value = route.query.query;
|
||||||
performSearch(route.query.query);
|
|
||||||
} else {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useHead(() => ({
|
useHead(() => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user