File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div id =" show-blogs" >
3
3
<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" >
5
6
<h2 >{{ blog.title | to-uppercase }}</h2 >
6
7
<article >{{ blog.body }}</article >
7
8
</div >
12
13
export default {
13
14
data () {
14
15
return {
15
- blogs: []
16
+ blogs: [],
17
+ search: ' '
16
18
}
17
19
},
18
20
methods: {
@@ -22,6 +24,13 @@ export default {
22
24
this .$http .get (' http://jsonplaceholder.typicode.com/posts' ).then (function (data ){
23
25
this .blogs = data .body .slice (0 ,10 );
24
26
});
27
+ },
28
+ computed: {
29
+ filteredBlogs : function (){
30
+ return this .blogs .filter ((blog ) => {
31
+ return blog .title .match (this .search );
32
+ });
33
+ }
25
34
}
26
35
}
27
36
</script >
You can’t perform that action at this time.
0 commit comments