Skip to content

Commit 9c1c6a0

Browse files
author
Shaun Pelling
committed
added lesson 36 code
1 parent 8518562 commit 9c1c6a0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/showBlogs.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<template>
22
<div id="show-blogs">
33
<h1>All Blog Articles</h1>
4-
<div v-for="blog in blogs" class="single-blog">
4+
<input type="text" v-model="search" placeholder="search blogs" />
5+
<div v-for="blog in filteredBlogs" class="single-blog">
56
<h2>{{ blog.title | to-uppercase }}</h2>
67
<article>{{ blog.body }}</article>
78
</div>
@@ -12,7 +13,8 @@
1213
export default {
1314
data () {
1415
return {
15-
blogs: []
16+
blogs: [],
17+
search: ''
1618
}
1719
},
1820
methods: {
@@ -22,6 +24,13 @@ export default {
2224
this.$http.get('http://jsonplaceholder.typicode.com/posts').then(function(data){
2325
this.blogs = data.body.slice(0,10);
2426
});
27+
},
28+
computed: {
29+
filteredBlogs: function(){
30+
return this.blogs.filter((blog) => {
31+
return blog.title.match(this.search);
32+
});
33+
}
2534
}
2635
}
2736
</script>

0 commit comments

Comments
 (0)