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