Created
June 30, 2017 17:08
-
-
Save nuria-fl/93e3bb6f18faf22ef6b9b0ff20d265a6 to your computer and use it in GitHub Desktop.
Vue tutorial: Comunicación con la api
This file contains hidden or 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
//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); | |
}); | |
} | |
} |
This file contains hidden or 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> | |
<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