Skip to content

Instantly share code, notes, and snippets.

@rg3915
Last active November 13, 2021 17:05
Show Gist options
  • Save rg3915/dc9f6f824771821f1f6128dc21ae4d84 to your computer and use it in GitHub Desktop.
Save rg3915/dc9f6f824771821f1f6128dc21ae4d84 to your computer and use it in GitHub Desktop.
List all my gists with VueJS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="http://html5-training-in-hyderabad.blogspot.com.br/favicon.ico">
<title>My Gist</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Font-awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- VueJS -->
<script src="https://unpkg.com/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- Bootstrap core JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- https://fiddle.jshell.net/sL4w9wc9/16/ -->
<div id="app" class="container">
<ul class="pagination">
<li><a @click="listar_gists(1)">1</a></li>
<li><a @click="listar_gists(2)">2</a></li>
<li><a @click="listar_gists(3)">3</a></li>
</ul>
<div>
<input type="text" v-model="search" placeholder="Search..." />
</div>
<table class="table">
<tbody>
<tr v-for="item in filteredItems">
<td><a :href="item.url" target="_blank">{{ item.description }}</a></td>
</tr>
</tbody>
</table>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
items: [],
search: ''
},
methods: {
listar_gists(page){
axios.get('https://api.github.com/users/rg3915/gists?page=' + page)
.then((result) => {
this.items = result.data.map((item) => {
return {description: item.description, url: item.html_url}
})
})
}
},
mounted(){
this.listar_gists(1)
},
computed: {
filteredItems(){
return this.items.filter((item) => {
return item.description.toLowerCase().indexOf(this.search.toLowerCase())>=0;
});
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment