Last active
August 16, 2018 15:09
-
-
Save Gregg/a867b48e3ef62d5581bcadd3b0682cca to your computer and use it in GitHub Desktop.
Axios Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>Events Listing</h1> | |
<EventCard v-for="event in events" :key="event.id" :event="event"/> | |
</div> | |
</template> | |
<script> | |
import EventCard from '@/components/EventCard.vue' | |
import EventService from '@/services/EventService.js' | |
export default { | |
components: { | |
EventCard | |
}, | |
data() { | |
return { | |
events: [] | |
} | |
}, | |
mounted() { | |
EventService.getEvents() | |
.then(response => { | |
this.events = response.data | |
}) | |
.catch(error => { | |
console.log('There was an error:', error.response) | |
}) | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
export default { | |
getEvents() { | |
return this.api().get('/events') | |
}, | |
api() { | |
return axios.create({ | |
baseURL: `http://localhost:3000`, | |
withCredentials: false, | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json' | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment