-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.vue
52 lines (49 loc) · 1.35 KB
/
app.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
52
<script lang="ts" setup>
import type { ISetResponse, ITodo } from 'types'
interface IAllItems extends ISetResponse {
data: ITodo[]
}
const { data: items, refresh, error } = await useFetch<IAllItems>('/api/v1/item/all-items')
if (error.value) {
throw createError(error.value)
}
</script>
<template>
<div class="p-20 flex justify-center">
<div class="max-w-xl w-full bg-white p-4 rounded shadow-md">
<h1 class="text-slate-800 text-xl font-bold text-center">Simple MongoDB Crud Example. Nuxt 3</h1>
<div class="mt-6">
<TheForm @add-item="refresh" />
<div class="text-slate-400 text-xs mt-2">Total: {{ items?.data.length }}</div>
<ul
v-if="items!.data.length > 0"
class="mt-4 divide-y"
>
<TheItem
v-for="item in items!.data"
:item="item"
@delete="refresh"
@update="refresh"
/>
</ul>
<div
v-else
class="text-slate-400 text-center mt-4"
>
Oops! Looks like there are no items yet. Add some.
</div>
</div>
<NuxtErrorBoundary>
<!-- ... -->
<template #error>
<p>An error occurred: {{ error }}</p>
</template>
</NuxtErrorBoundary>
</div>
</div>
</template>
<style scoped lang="css">
:global(body) {
@apply bg-slate-100;
}
</style>