Created
January 27, 2018 02:01
-
-
Save hibuno/f9c79f3d05c85da27f49960d0d6ddcb2 to your computer and use it in GitHub Desktop.
Add axios and function to get 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
<template> | |
<div class="mt-5"> | |
<div class="row"> | |
<div class="col-12" v-for="item in posts" v-bind:key="item.key"> | |
<div class="card"> | |
<div class="card-body"> | |
<h5 class="card-title">{{ item.title }}</h5> | |
<h6 class="card-subtitle mb-2 text-muted">{{ item.publishedAt }}</h6> | |
<p class="card-text">{{ item.description }}</p> | |
<a href="#" class="card-link">Card link</a> | |
<a href="#" class="card-link">Another link</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import axios from 'axios' | |
export default { | |
data () { | |
return { | |
allPost: [], | |
posts: [] | |
} | |
}, | |
mounted () { | |
axios('https://newsapi.org/v2/everything?q=programming&domains=techcrunch.com,techinasia.com&apiKey=API_KEY', { | |
crossDomain: true | |
}).then( ({ data }) => { | |
this.allPost = data.articles | |
data.articles.map((item, key) => { | |
if (item.description !== null && this.posts.length < 9) { | |
this.posts.push(item) | |
} | |
}) | |
}) | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment