-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.vue
More file actions
60 lines (57 loc) · 1.49 KB
/
Copy pathapp.vue
File metadata and controls
60 lines (57 loc) · 1.49 KB
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
53
54
55
56
57
58
59
60
<template>
<div>
<div style="margin: 8px">
<input type="text" placeholder="Describe Stuff" v-model="stuffInput" />
</div>
<div style="margin: 8px">
<label for="important">
<span>Important</span>
<input
v-model="importantInput"
name="important"
type="checkbox"
placeholder="Important"
/>
</label>
</div>
<div style="margin: 8px">
<button @click="addStuffToDatabase">ADD TO DATABASE</button>
</div>
</div>
<div>
<p v-if="newRecordError">Error Adding Record {{ newRecordError }}</p>
</div>
<div>
<div v-for="item in stuffResults" :key="item.id">
<p>{{ item }}</p>
</div>
</div>
</template>
<script setup lang="ts">
import { NuxtError } from "nuxt/app";
import { basicFunction, addTheStuff, getAllTheStuff } from "./lib/api.server";
const stuffInput = ref();
const importantInput = ref();
const newRecordResult = ref();
const newRecordError = ref();
const basicResult = await basicFunction("Aaron Saunders");
const { data: stuffResults, error: stuffResultsError } = useAsyncData(
"stuff",
() => getAllTheStuff(),
{ watch: [newRecordResult] }
);
/**
*
*/
const addStuffToDatabase = async () => {
try {
newRecordResult.value = await addTheStuff({
stuff: stuffInput.value,
important: importantInput.value ? 1 : 0,
});
console.log(newRecordResult.value);
} catch (error) {
newRecordError.value = (error as NuxtError).data?.message;
}
};
</script>