Skip to content

Instantly share code, notes, and snippets.

@hibuno
Created January 27, 2018 02:01
Show Gist options
  • Save hibuno/f9c79f3d05c85da27f49960d0d6ddcb2 to your computer and use it in GitHub Desktop.
Save hibuno/f9c79f3d05c85da27f49960d0d6ddcb2 to your computer and use it in GitHub Desktop.
Add axios and function to get API
<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