mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
639 B
40 lines
639 B
6 years ago
|
<script>
|
||
|
import { onMount } from 'svelte';
|
||
|
|
||
|
let photos = [];
|
||
|
|
||
|
onMount(async () => {
|
||
3 years ago
|
const res = await fetch(`/tutorial/api/album`);
|
||
6 years ago
|
photos = await res.json();
|
||
|
});
|
||
|
</script>
|
||
|
|
||
4 years ago
|
<h1>Photo album</h1>
|
||
|
|
||
|
<div class="photos">
|
||
|
{#each photos as photo}
|
||
|
<figure>
|
||
1 year ago
|
<img src={photo.thumbnailUrl} alt={photo.title} />
|
||
4 years ago
|
<figcaption>{photo.title}</figcaption>
|
||
|
</figure>
|
||
|
{:else}
|
||
|
<!-- this block renders when photos.length === 0 -->
|
||
|
<p>loading...</p>
|
||
|
{/each}
|
||
|
</div>
|
||
|
|
||
6 years ago
|
<style>
|
||
|
.photos {
|
||
|
width: 100%;
|
||
|
display: grid;
|
||
|
grid-template-columns: repeat(5, 1fr);
|
||
|
grid-gap: 8px;
|
||
|
}
|
||
|
|
||
1 year ago
|
figure,
|
||
|
img {
|
||
6 years ago
|
width: 100%;
|
||
|
margin: 0;
|
||
|
}
|
||
|
</style>
|