Created
July 10, 2017 11:31
-
-
Save yann-yinn/8a2d0490fe99d783ba43c64b7b16e54b to your computer and use it in GitHub Desktop.
Nuxt js get recipes from contenta public API with axios
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> | |
| <section class="recipes"> | |
| <h1>Our latest recipes</h1> | |
| <div v-for="recipe in recipes"> | |
| <h2> {{recipe.title}} </h2> | |
| <p> {{recipe.difficulty}} </p> | |
| <div v-if="recipe.image"> | |
| <img width="300px" :src="recipe.image.thumbnail.filename" /> | |
| </div> | |
| </div> | |
| </section> | |
| </template> | |
| <script> | |
| import axios from 'axios' | |
| import jsonapiParser from 'jsonapi-parse' | |
| export default { | |
| async asyncData () { | |
| const result = await axios.get('https://dev-contentacms.pantheonsite.io/api/recipes?sort=-created&page[limit]=20&include=image,image.thumbnail&fields[recipes]=image,title,difficulty&fields[files]=filename') | |
| const recipes = jsonapiParser.parse(result.data).data | |
| console.log(recipes) | |
| return { recipes } | |
| } | |
| } | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment