1
0
mirror of https://github.com/sendevia/website.git synced 2026-03-06 07:40:50 +08:00

search: 默认不显示全部文章

This commit is contained in:
2025-10-09 18:44:40 +08:00
parent 7ed26d2805
commit b470cebb69

View File

@@ -4,9 +4,8 @@ import { useAllPosts } from "../composables/useAllPosts";
const posts = useAllPosts(true);
const query = ref("");
const filteredPosts = computed(() => {
if (!query.value) return posts.value;
if (!query.value) return [];
const q = query.value.toLowerCase();
return posts.value.filter((post) => post.title.toLowerCase().includes(q) || (post.content && post.content.toLowerCase().includes(q)));
});
@@ -15,13 +14,16 @@ const filteredPosts = computed(() => {
<template>
<div class="page-search">
<input v-model="query" placeholder="搜索文章..." class="search-input" />
<div class="search-result" v-if="filteredPosts.length">
<div v-for="post in filteredPosts" :key="post.url">
<a :href="post.url">{{ post.title }}</a>
<span v-if="post.date"> - {{ post.date }}</span>
<div v-if="query">
<div class="search-result" v-if="filteredPosts.length">
<div v-for="post in filteredPosts" :key="post.url">
<a :href="post.url">{{ post.title }}</a>
<span v-if="post.date"> - {{ post.date }}</span>
</div>
</div>
<p v-else>没有找到相关文章</p>
</div>
<p v-else>没有找到相关文章</p>
<p v-else>请输入关键词以搜索文章</p>
</div>
</template>