blob: 77d83da553bfe1e1357162ac4a9ee39e5924d844 (
plain)
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
|
<script setup lang="js">
import { ref, toRaw } from 'vue'
import axios from 'axios'
import { useToast } from 'vue-toast-notification'
const emit = defineEmits(["added"])
const toast = useToast({
position: 'top-right'
})
const brandName = ref('')
const submit = async (e) => {
e.preventDefault()
try {
await axios.post('/brand', {
name: toRaw(brandName.value)
})
toast.success('Successfully added a new brand.')
emit("added")
brandName.value = ''
} catch (err) {
toast.error('An unhandled exception occoured. Please check logs')
console.error(err)
}
}
</script>
<template>
<form class="d-flex align-items-center justify-content-center m-3" v-on:submit="submit">
<div class="form-floating">
<input
id="brand-name-input"
type="text"
class="form-control"
placeholder=""
v-model="brandName"
/>
<label for="brand-name-input">New Brand Name</label>
</div>
<div class="form-floating m-3">
<input type="submit" value="Add New Brand" class="btn btn-primary" />
</div>
</form>
</template>
|