Skip to content

Commit 1ff2bc9

Browse files
committed
feat: add home page search
1 parent fd46ad9 commit 1ff2bc9

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

components/ui/button/Button.vue

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script setup lang="ts">
2+
import type { VariantProps } from 'class-variance-authority'
3+
import { Primitive, type PrimitiveProps } from 'radix-vue'
4+
import { buttonVariants } from '.'
5+
import { cn } from '@/lib/utils'
6+
7+
interface ButtonVariantProps extends VariantProps<typeof buttonVariants> {}
8+
9+
interface Props extends PrimitiveProps {
10+
variant?: ButtonVariantProps['variant']
11+
size?: ButtonVariantProps['size']
12+
as?: string
13+
}
14+
15+
withDefaults(defineProps<Props>(), {
16+
variant: 'default',
17+
size: 'default',
18+
as: 'button',
19+
})
20+
</script>
21+
22+
<template>
23+
<Primitive
24+
:as="as"
25+
:as-child="asChild"
26+
:class="cn(buttonVariants({ variant, size }), $attrs.class ?? '')"
27+
>
28+
<slot />
29+
</Primitive>
30+
</template>

components/ui/button/index.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { cva } from 'class-variance-authority'
2+
3+
export { default as Button } from './Button.vue'
4+
5+
export const buttonVariants = cva(
6+
'inline-flex items-center justify-center rounded-md whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
7+
{
8+
variants: {
9+
variant: {
10+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
11+
destructive:
12+
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
13+
outline:
14+
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
15+
secondary:
16+
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
17+
ghost: 'hover:bg-accent hover:text-accent-foreground',
18+
link: 'text-primary underline-offset-4 hover:underline',
19+
},
20+
size: {
21+
default: 'h-10 px-4 py-2',
22+
sm: 'h-9 rounded-md px-3',
23+
lg: 'h-11 rounded-md px-8',
24+
icon: 'h-10 w-10',
25+
},
26+
},
27+
defaultVariants: {
28+
variant: 'default',
29+
size: 'default',
30+
},
31+
},
32+
)

pages/index.vue

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import { Input } from '@/components/ui/input';
3+
import { Button } from '@/components/ui/button';
4+
5+
const searchInput = ref('');
6+
const search = async () => {
7+
if (!searchInput.value) return;
8+
console.log(searchInput.value);
9+
const resp = await $fetch('/api/search/', {});
10+
console.log(resp);
11+
};
12+
</script>
213

314
<template>
4-
<NuxtWelcome />
15+
<!-- <NuxtWelcome /> -->
16+
<div class="main">
17+
<div class="mt-10">
18+
<span class="text-4xl font-bold">Get Bonus</span>
19+
</div>
20+
<div class="mt-8 flex gap-4">
21+
<Input v-model="searchInput" @keydown.enter="search"></Input>
22+
<Button @click="search">搜索</Button>
23+
</div>
24+
</div>
525
</template>
26+
27+
<style>
28+
.main {
29+
@apply: mx-auto w-5xl lt-lg:w-3xl lt-md:w-[95vw] lt-md:px-3;
30+
}
31+
</style>

server/api/search/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default defineEventHandler((event) => {
2+
return {
3+
hello: 'world'
4+
};
5+
});

0 commit comments

Comments
 (0)