Finished course by adding axios as a service
parent
34e7a8baf1
commit
233dc96986
@ -0,0 +1,49 @@
|
||||
{
|
||||
"events": [
|
||||
{
|
||||
"id": 5928101,
|
||||
"user": {
|
||||
"id": "abc123",
|
||||
"name": "Adam"
|
||||
},
|
||||
"category": "animal welfare",
|
||||
"organizer": "Adam",
|
||||
"title": "Cat Cabaret",
|
||||
"description": "Yay felines!",
|
||||
"location": "Meow Town",
|
||||
"date": "2019-01-03T21:54:00.000Z",
|
||||
"time": "2:00",
|
||||
"attendees": []
|
||||
},
|
||||
{
|
||||
"id": 8419988,
|
||||
"user": {
|
||||
"id": "abc123",
|
||||
"name": "Adam"
|
||||
},
|
||||
"category": "animal welfare",
|
||||
"organizer": "Adam",
|
||||
"title": "Kitty Cluster",
|
||||
"description": "Yay cats!",
|
||||
"location": "Catlandia",
|
||||
"date": "2019-01-31T22:09:00.000Z",
|
||||
"time": "7:00",
|
||||
"attendees": []
|
||||
},
|
||||
{
|
||||
"id": 4582797,
|
||||
"user": {
|
||||
"id": "abc123",
|
||||
"name": "Adam"
|
||||
},
|
||||
"category": "animal welfare",
|
||||
"organizer": "Adam",
|
||||
"title": "Puppy Parade",
|
||||
"description": "Yay pups!",
|
||||
"location": "Puptown ",
|
||||
"date": "2019-02-02T23:27:00.000Z",
|
||||
"time": "1:00",
|
||||
"attendees": []
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,19 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: 'http://localhost:3000',
|
||||
withCredentials: false,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
export default {
|
||||
getEvents() {
|
||||
return apiClient.get('/events')
|
||||
},
|
||||
getEvent(id) {
|
||||
return apiClient.get('/events/' + id)
|
||||
}
|
||||
}
|
@ -1,9 +1,74 @@
|
||||
<template>
|
||||
<h1>Showing Event #{{ event_id }}</h1>
|
||||
<div>
|
||||
<div class="event-header">
|
||||
<span class="eyebrow">@{{ event.time }} on {{ event.date }}</span>
|
||||
<h1 class="title">{{ event.title }}</h1>
|
||||
<h5>Organized by {{ event.organizer }}</h5>
|
||||
<h5>Category: {{ event.category }}</h5>
|
||||
</div>
|
||||
<BaseIcon name="map">
|
||||
<h2>Location</h2>
|
||||
</BaseIcon>
|
||||
<address>{{ event.location }}</address>
|
||||
<h2>Event details</h2>
|
||||
<p>{{ event.description }}</p>
|
||||
<h2>
|
||||
Attendees
|
||||
<span class="badge -fill-gradient">{{
|
||||
event.attendees ? event.attendees.length : 0
|
||||
}}</span>
|
||||
</h2>
|
||||
<ul class="list-group">
|
||||
<li
|
||||
v-for="(attendee, index) in event.attendees"
|
||||
:key="index"
|
||||
class="list-item"
|
||||
>
|
||||
<b>{{ attendee.name }}</b>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import EventService from '@/services/EventService'
|
||||
export default {
|
||||
props: ['event_id']
|
||||
props: ['id'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
event: {}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
EventService.getEvent(this.id)
|
||||
.then(response => {
|
||||
this.event = response.data
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('An error occured: ' + error.status)
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.location {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.location > .icon {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.event-header > .title {
|
||||
margin: 0;
|
||||
}
|
||||
.list-group {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.list-group > .list-item {
|
||||
padding: 1em 0;
|
||||
border-bottom: solid 1px #e5e5e5;
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue