-
Notifications
You must be signed in to change notification settings - Fork 6
/
TheHeader.vue
51 lines (49 loc) · 1.52 KB
/
TheHeader.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script lang="ts" setup>
const { result, search } = useSearch("headless_commerce");
const hits = ref([]);
const fetchSearchResults = async (e) => {
await search({ query: e.target.value });
hits.value = result.value.hits;
};
</script>
<template>
<nav class="py-2 relative w-full">
<div class="px-6 flex items-center">
<NuxtLink to="/">
<img class="h-20 w-20 mr-16" src="/logo.svg" alt="Store logo" />
</NuxtLink>
<div class="flex justify-center relative">
<div class="mb-3 w-96">
<input
type="search"
class="block w-full px-3 py-1 bg-white bg-clip-padding border border-solid border-gray-300 rounded"
id="search"
placeholder="Search for products"
@input="fetchSearchResults"
/>
</div>
<div
v-if="hits.length"
class="flex justify-center absolute top-10 z-10"
>
<ul class="bg-white border border-gray-200 w-96 text-gray-900">
<li
v-for="hit in hits"
:key="hit.objectID"
class="px-6 py-2 border-b border-gray-200 w-full"
@click="hits = []"
>
<NuxtLink
:to="`/products/${hit.Handle}`"
class="flex items-center"
>
<img class="w-20" :src="hit['Image Src']" />
<p class="ml-4">{{ hit.Title }}</p>
</NuxtLink>
</li>
</ul>
</div>
</div>
</div>
</nav>
</template>