Last change
on this file since dad25fc was dad25fc, checked in by Aleksandarj03 <138524804+Aleksandarj03@…>, 42 hours ago |
Rewrote logic for login and register and added Add Restaurant functionality for the admin
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | <script>
|
---|
2 | import { useRouter } from 'vue-router'
|
---|
3 | import { restaurantStore } from '@/PiniaStores/restaurantStore.js'
|
---|
4 | import { userStore } from '@/PiniaStores/UserStore.js'
|
---|
5 |
|
---|
6 |
|
---|
7 | export default {
|
---|
8 | data() {
|
---|
9 | return {
|
---|
10 | router: useRouter(),
|
---|
11 | name: '',
|
---|
12 | url: 'http://localhost:8080/api/admin/add',
|
---|
13 | restaurantStore: restaurantStore(),
|
---|
14 | userStore: userStore(),
|
---|
15 | }
|
---|
16 | },
|
---|
17 | methods: {
|
---|
18 | async addRestaurant() {
|
---|
19 | await fetch(this.url, {
|
---|
20 | method: 'POST',
|
---|
21 | headers: {
|
---|
22 | 'Content-Type': 'application/json',
|
---|
23 | 'Authorization': this.userStore.getToken
|
---|
24 | },
|
---|
25 | body: JSON.stringify({
|
---|
26 | name: this.name,
|
---|
27 | })
|
---|
28 | }).then((response) => response.json())
|
---|
29 | .then(json => {this.restaurantStore.newRestaurant(json)})
|
---|
30 |
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 | </script>
|
---|
35 |
|
---|
36 | <template>
|
---|
37 | <div class="container mt-5">
|
---|
38 | <div class="row justify-content-center">
|
---|
39 | <div class="col-4">
|
---|
40 | <form v-on:submit.prevent="addRestaurant">
|
---|
41 | <div class="mb-3">
|
---|
42 | <label for="name" class="form-label" >Restaurant name</label>
|
---|
43 | <input v-model="this.name" type="text" id="name" name="name" class="form-control" placeholder="Name" required>
|
---|
44 | </div>
|
---|
45 | <button type="submit" class="btn btn-primary">Add Restaurant</button>
|
---|
46 | </form>
|
---|
47 | </div>
|
---|
48 | </div>
|
---|
49 | </div>
|
---|
50 | </template>
|
---|
51 |
|
---|
52 | <style scoped></style>
|
---|
Note:
See
TracBrowser
for help on using the repository browser.