Skip to content

Instantly share code, notes, and snippets.

@wesleyguirra
Last active May 31, 2017 03:26
Show Gist options
  • Save wesleyguirra/8645a6de1059daa184a15a3e0690cae6 to your computer and use it in GitHub Desktop.
Save wesleyguirra/8645a6de1059daa184a15a3e0690cae6 to your computer and use it in GitHub Desktop.
/**
* Created by wesleyguirra on 5/26/17.
*/
import axios from 'axios'
const client = axios.create({baseURL: 'http://localhost:4567/api/v1', headers: {'Authorization': localStorage.getItem('token')}})
axios.interceptors.response.use((response) => {
return response
}, function (error) {
if (error.response.status === 401) {
console.log('unauthorized, logging out ...')
}
return Promise.reject(error)
})
export default client
<script>
import CcButton from './Button'
import { getMedics } from '../services/medics'
export default {
data () {
return {
medics: ''
}
},
components: {
CcButton
},
methods: {
fetchUsers () {
console.log(getMedics())
}
},
mounted () {
setTimeout(() => {
this.fetchUsers()
}, 2000)
}
}
</script>
/**
* Created by wesleyguirra on 5/30/17.
*/
import http from './http'
export function getMedics () {
return http.get('medic')
.then(function (response) {
console.log(response.data)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment