Skip to content

Instantly share code, notes, and snippets.

@nuria-fl
Created June 30, 2017 17:08
Show Gist options
  • Save nuria-fl/93e3bb6f18faf22ef6b9b0ff20d265a6 to your computer and use it in GitHub Desktop.
Save nuria-fl/93e3bb6f18faf22ef6b9b0ff20d265a6 to your computer and use it in GitHub Desktop.
Vue tutorial: Comunicación con la api
//src/services/api.js
import axios from 'axios'
const host = 'https://api.themoviedb.org/3'
const apiKey = 'api_key=4bcacd5bcdf6d2ae0125c890eab6e4ae';
export default {
getMovies() {
return axios.get(`${host}/discover/movie?${apiKey}`)
.then(function (response) {
return response.data.results;
})
.catch(function (error) {
console.log(error);
});
}
}
<template>
<div>
<article v-for="movie in movies">
<img :src="`https://image.tmdb.org/t/p/w500/${movie.poster_path}`" alt="">
<h4>{{ movie.title }}</h4>
<p>{{movie.vote_average}}</p>
</article>
</div>
</template>
<script>
import api from '@/services/api'
export default {
data () {
return {
movies: []
}
},
created() {
api.getMovies().then(data => {
this.movies = data
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment