Skip to content

Commit b599869

Browse files
committed
feature: fetch posts
1 parent 89b9ef4 commit b599869

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

blog/src/pages/Index.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
// Index.vue
12
<template>
23
<div class="container">
3-
Index
4+
<div class="row" v-for="i in Math.ceil(posts.length / 5)" style="margin-top: 25px">
5+
<div class="column column-20" v-for="post in posts.slice((i - 1) * 5, i * 5)">
6+
<div class="card">
7+
<img src="https://fakeimg.pl/300/">
8+
<h5 v-html="post.title.rendered"></h5>
9+
<p>{{ new Date(post.date_gmt).toLocaleString('it-IT', { year: 'numeric', month: 'numeric', day: 'numeric' }) }}</p>
10+
</div>
11+
</div>
12+
</div>
413
</div>
514
</template>
615

@@ -15,7 +24,25 @@ export default {
1524
},
1625
1726
async mounted() {
18-
const posts = await fetch('https://jsonplaceholder.typicode.com/posts');
27+
const postsRequest = await fetch('https://blog.enricodeleo.com/wp-json/wp/v2/posts');
28+
try {
29+
const posts = this.posts = await postsRequest.json();
30+
} catch (error) {
31+
console.log(error);
32+
}
1933
},
2034
}
21-
</script>
35+
</script>
36+
37+
<style lang="scss">
38+
.card {
39+
background: white;
40+
padding: 0 0 5px 0;
41+
border-radius: 5px;
42+
43+
p,
44+
h5 {
45+
padding: 0 10px;
46+
}
47+
}
48+
</style>

0 commit comments

Comments
 (0)