Skip to content

Instantly share code, notes, and snippets.

Created July 7, 2017 21:04
Show Gist options
  • Save anonymous/cb0cddea1fbf0134ee7942638da2f4d5 to your computer and use it in GitHub Desktop.
Save anonymous/cb0cddea1fbf0134ee7942638da2f4d5 to your computer and use it in GitHub Desktop.
Svelte component
<h1 class="text-center">Example</h1>
<div class="list">
{{#each results as result @id}}
<Card result={{result}} />
{{/each}}
</div>
<script>
import Card from './Card.html';
const SEARCH = '//api.github.com/search/repositories';
export default {
async oncreate() {
let res = await fetch(`${SEARCH}?q=svelte`),
json = await res.json();
this.set({results: json && json.items || []});
},
data() {
return {
results: ''
}
},
components: {
Card
}
}
</script>
<style>
.text-center {
text-align: center;
}
</style>
<div class="card">
<a href={{result.html_url}} target="_blank">
{{result.full_name}}
</a>
🌟<strong>{{result.stargazers_count}}</strong>
<p>{{result.description}}</p>
</div>
<style>
.card {
padding: 10px;
margin: 10px;
background: white;
box-shadow: 0 1px 5px rgba(0,0,0,0.5);
}
</style>
{
"name": "world"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment