Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

ContactForm.vue

61 lines1.4 KB

1<script setup lang="ts">
2import { useRouter } from 'vue-router'
3import type { Contact } from './services/contacts/types'
4​
5defineProps<{ contact?: Contact }>()
6const emit = defineEmits<{ submit: [formData: FormData] }>()
7​
8const router = useRouter()
9​
10const onSubmit = (event: SubmitEvent) => {
11 emit('submit', new FormData(event.currentTarget as HTMLFormElement))
13</script>
14​
15<template>
16 <form id="contact-form" @submit.prevent="onSubmit">
17 <p>
18 <span>Name</span>
19 <input
20 placeholder="First"
21 aria-label="First name"
22 type="text"
23 name="first"
24 :value="contact?.first"
25 />
26 <input
27 placeholder="Last"
28 aria-label="Last name"
29 type="text"
30 name="last"
31 :value="contact?.last"
32 />
33 </p>
34 <label>
35 <span>Twitter</span>
36 <input
37 type="text"
38 name="twitter"
39 placeholder="@jack"
40 :value="contact?.twitter"
41 />
42 </label>
43 <label>
44 <span>Avatar URL</span>
45 <input
46 placeholder="https://example.com/avatar.jpg"
47 type="text"
48 name="avatar"
49 :value="contact?.avatar"
50 />
51 </label>
52 <label>
53 <span>Notes</span>
54 <textarea name="notes" :value="contact?.notes" rows="6" />
55 </label>
56 <p>
57 <button type="submit">Save</button>
58 <button type="button" @click="router.back()">Cancel</button>
59 </p>
60 </form>
61</template>