Skip to content

Instantly share code, notes, and snippets.

@akbarsahata
Created November 23, 2017 04:27
Show Gist options
  • Save akbarsahata/93dde226fb0ffeb9fd871f972b5fc827 to your computer and use it in GitHub Desktop.
Save akbarsahata/93dde226fb0ffeb9fd871f972b5fc827 to your computer and use it in GitHub Desktop.
miracle-fox vue component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hacktiv8 Job Boards</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
</head>
<body>
<div id="app" class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="alert alert-danger">News Unread {{totalNews}}</div>
<news-item v-for="(news, index) in newsList" :key="index" :article="news" :index="index" @unread-minus-one="deleteNews"/>
</div>
</div>
</div>
</body>
<script src="https://unpkg.com/vue "></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.1/axios.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="/js/news-item.js"></script>
<script>
new Vue({
el: '#app',
data: {
newsList: [],
totalNews: 0
},
methods: {
deleteNews: function (payload) {
this.totalNews--
let index = 0
this.newsList.forEach(n => {
if (n.title === payload.title) {
this.newsList.splice(index, 1)
return
}
index++
})
}
},
created: function () {
axios.get('https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=5981474fde55432a9656bea68c9267bd')
.then(({data}) => {
this.newsList = data.articles
this.totalNews = data.articles.length
})
.catch(err => console.log(err))
}
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment