Skip to content

Commit

Permalink
feat: generate url
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 24, 2024
1 parent 78f244d commit 829e86a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
const route = useRoute();
const router = useRouter();
const results = ref<Detail[]>();
const { data } = await useAsyncData('search_results', async () =>
route.query.q ? $fetch(`/api/search/${route.query.q}`) : undefined
);
const results = ref<Detail[] | null>(data.value?.result ?? null);
const searchInput = ref('');
const isSearching = ref(false);
const search = async () => {
if (isSearching.value) return;
if (!searchInput.value) return;
router.push({
path: route.path,
query: { q: searchInput.value }
});
try {
isSearching.value = true;
const resp = await $fetch(`/api/search/${searchInput.value}`, {});
Expand All @@ -26,11 +37,6 @@ const search = async () => {
isSearching.value = false;
}
};
if (route.query.q) {
searchInput.value = route.query.q as string;
await search();
}
</script>

<template>
Expand Down

0 comments on commit 829e86a

Please sign in to comment.