-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
66 lines (62 loc) · 1.85 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
<div class="min-h-screen max-w-[500px] mx-auto px-[30px] md:px-[0px]">
<h1 class="font-extrabold text-4xl pt-[60px]">Hellow im dago</h1>
<form ref="msg_form" @submit.prevent="onSubmit" class="mt-[30px]">
<h2 class="font-medium text-2xl">Send me a message</h2>
<div class="mt-[10px]">
<label for="msg-inp" class="block sr-only">Message</label>
<input
type="text"
id="msg-inp"
v-model="msg"
class="block w-full px-[20px] py-[16px] border rounded-xl"
required
/>
</div>
<div class="mt-[30px]">
<button
:disabled="is_fetching ? true : false"
class="border border-gray-800 px-[30px] py-[10px] rounded-xl"
>
Send
</button>
</div>
</form>
<div
class="fixed bottom-0 left-0 w-full h-auto border-red-500 border-t-4 p-[30px] min-h-[200px] bg-red-100"
v-if="fetch_error"
>
<code class="text-red-800">{{ fetch_error }}</code>
</div>
<div
class="fixed bottom-0 left-0 w-full h-auto border-blue-500 border-t-4 p-[30px] min-h-[200px] bg-blue-100"
v-if="form_sended"
>
<code class="text-blue-800">Message recived</code>
</div>
</div>
</template>
<script setup>
import { usePostQuery_with_throw } from "./composables/usePostQuery";
const msg_form = ref("");
const msg = ref("");
const form_sended = ref(false);
const fetch_error = ref(false);
const { is_fetching, load } = usePostQuery_with_throw();
async function onSubmit() {
form_sended.value = false;
fetch_error.value = false;
const data = {
message: msg.value,
};
try {
const res = await load("/api/message", data);
console.log({ res });
form_sended.value = true;
} catch (error) {
is_fetching.value =
console.error(error);
fetch_error.value = error;
}
}
</script>