Skip to content

Commit a00ffbf

Browse files
committed
feature: single posts
1 parent b599869 commit a00ffbf

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

blog/src/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<header class="header-main">
55
<div class="row">
66
<div class="column text-center">
7-
<h2 class="no-margin"><strong>My Blog</strong></h2>
7+
<router-link :to="{ name: 'index' }">
8+
<h2 class="no-margin"><strong>My Blog</strong></h2>
9+
</router-link>
810
</div>
911
</div>
1012
</header>
@@ -78,4 +80,8 @@ export default {
7880
padding: 1rem 0;
7981
}
8082
83+
.header-main {
84+
margin-bottom: 20px;
85+
}
86+
8187
</style>

blog/src/pages/Index.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
<div class="container">
44
<div class="row" v-for="i in Math.ceil(posts.length / 5)" style="margin-top: 25px">
55
<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>
6+
<router-link :to="{ name: 'single', params: { id: post.id }}">
7+
<div class="card">
8+
<img src="https://fakeimg.pl/300/">
9+
<h5 v-html="post.title.rendered"></h5>
10+
<p>{{ new Date(post.date_gmt).toLocaleString('it-IT', { year: 'numeric', month: 'numeric', day: 'numeric' }) }}</p>
11+
</div>
12+
</router-link>
1113
</div>
1214
</div>
1315
</div>

blog/src/pages/Single.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
<template>
22
<div class="container">
3-
Single
3+
<div class="row">
4+
<div class="column">
5+
<h3 v-html="post.title.rendered"></h3>
6+
</div>
7+
</div>
8+
<div class="row">
9+
<div class="column" v-html="post.content.rendered"></div>
10+
</div>
411
</div>
512
</template>
613

714
<script>
815
export default {
916
name: 'SinglePage',
17+
18+
data() {
19+
return {
20+
post: [],
21+
};
22+
},
23+
24+
async mounted() {
25+
const postsRequest = await fetch(`https://blog.enricodeleo.com/wp-json/wp/v2/posts/${this.$route.params.id}`);
26+
try {
27+
const post = this.post = await postsRequest.json();
28+
} catch (error) {
29+
console.log(error);
30+
}
31+
},
1032
}
1133
</script>

0 commit comments

Comments
 (0)