Skip to content

Commit 10edba9

Browse files
author
Shaun Pelling
committed
added lesson 42 code
1 parent f77eb4d commit 10edba9

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/components/showBlogs.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1>All Blog Articles</h1>
44
<input type="text" v-model="search" placeholder="search blogs" />
55
<div v-for="blog in filteredBlogs" class="single-blog">
6-
<h2>{{ blog.title }}</h2>
6+
<router-link v-bind:to="'/blog/' + blog.id"><h2>{{ blog.title }}</h2></router-link>
77
<article>{{ blog.body }}</article>
88
</div>
99
</div>
@@ -40,4 +40,9 @@ export default {
4040
box-sizing: border-box;
4141
background: #eee;
4242
}
43+
44+
#show-blogs a{
45+
color: #444;
46+
text-decoration: none;
47+
}
4348
</style>

src/components/singleBlog.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div id="single-blog">
3+
<h1>{{ blog.title }}</h1>
4+
<article>{{ blog.body }}</article>
5+
</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
// Imports
11+
import searchMixin from '../mixins/searchMixin';
12+
13+
export default {
14+
data () {
15+
return {
16+
id: this.$route.params.id,
17+
blog: {}
18+
}
19+
},
20+
created() {
21+
this.$http.get('http://jsonplaceholder.typicode.com/posts/' + this.id).then(function(data){
22+
// console.log(data);
23+
this.blog = data.body;
24+
});
25+
}
26+
}
27+
</script>
28+
29+
<style>
30+
#single-blog{
31+
max-width: 960px;
32+
margin: 0 auto;
33+
}
34+
</style>

src/routes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import addBlog from './components/addBlog.vue';
22
import showBlogs from './components/showBlogs.vue';
3+
import singleBlog from './components/singleBlog.vue';
34

45
export default [
56
{ path: '/', component: showBlogs},
6-
{ path: '/add', component: addBlog}
7+
{ path: '/add', component: addBlog},
8+
{ path: '/blog/:id', component: singleBlog}
79
]

0 commit comments

Comments
 (0)