File tree Expand file tree Collapse file tree 5 files changed +60
-33
lines changed Expand file tree Collapse file tree 5 files changed +60
-33
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
3
<show-blogs ></show-blogs >
4
+ <list-blogs ></list-blogs >
4
5
</div >
5
6
</template >
6
7
7
8
<script >
8
9
// Imports
9
10
import showBlogs from ' ./components/showBlogs.vue' ;
11
+ import listBlogs from ' ./components/listBlogs.vue' ;
10
12
11
13
export default {
12
14
components: {
13
- ' show-blogs' : showBlogs
15
+ ' show-blogs' : showBlogs,
16
+ ' list-blogs' : listBlogs
14
17
},
15
18
data () {
16
19
return {
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div id =" show-blogs" >
3
+ <h1 >List Blog Titles</h1 >
4
+ <input type =" text" v-model =" search" placeholder =" search blogs" />
5
+ <div v-for =" blog in filteredBlogs" class =" single-blog" >
6
+ <h2 >{{ blog.title }}</h2 >
7
+ </div >
8
+ </div >
9
+ </template >
10
+
11
+ <script >
12
+ // Imports
13
+ import searchMixin from ' ../mixins/searchMixin' ;
14
+
15
+ export default {
16
+ data () {
17
+ return {
18
+ blogs: [],
19
+ search: ' '
20
+ }
21
+ },
22
+ created () {
23
+ this .$http .get (' http://jsonplaceholder.typicode.com/posts' ).then (function (data ){
24
+ this .blogs = data .body .slice (0 ,10 );
25
+ });
26
+ },
27
+ mixins: [searchMixin]
28
+ }
29
+ </script >
30
+
31
+ <style >
32
+ #show-blogs {
33
+ max-width : 800px ;
34
+ margin : 0px auto ;
35
+ }
36
+ .single-blog {
37
+ padding : 20px ;
38
+ margin : 20px 0 ;
39
+ box-sizing : border-box ;
40
+ background : #eee ;
41
+ }
42
+ </style >
Original file line number Diff line number Diff line change 3
3
<h1 >All Blog Articles</h1 >
4
4
<input type =" text" v-model =" search" placeholder =" search blogs" />
5
5
<div v-for =" blog in filteredBlogs" class =" single-blog" >
6
- <h2 v-rainbow >{{ blog.title | toUppercase }}</h2 >
6
+ <h2 >{{ blog.title }}</h2 >
7
7
<article >{{ blog.body }}</article >
8
8
</div >
9
9
</div >
10
10
</template >
11
11
12
12
<script >
13
+ // Imports
14
+ import searchMixin from ' ../mixins/searchMixin' ;
15
+
13
16
export default {
14
17
data () {
15
18
return {
16
19
blogs: [],
17
20
search: ' '
18
21
}
19
- },
20
- methods: {
21
-
22
22
},
23
23
created () {
24
24
this .$http .get (' http://jsonplaceholder.typicode.com/posts' ).then (function (data ){
25
25
this .blogs = data .body .slice (0 ,10 );
26
26
});
27
27
},
28
- computed: {
29
- filteredBlogs : function (){
30
- return this .blogs .filter ((blog ) => {
31
- return blog .title .match (this .search );
32
- });
33
- }
34
- },
35
- filters: {
36
- /* 'to-uppercase': function(value){
37
- return value.toUpperCase();
38
- }*/
39
- toUppercase (value ){
40
- return value .toUpperCase ();
41
- }
42
- },
43
- directives: {
44
- ' rainbow' : {
45
- bind (el , binding , vnode ){
46
- el .style .color = " #" + Math .random ().toString (16 ).slice (2 , 8 );
47
- }
48
- }
49
- }
28
+ mixins: [searchMixin]
50
29
}
51
30
</script >
52
31
Original file line number Diff line number Diff line change @@ -5,12 +5,6 @@ import App from './App.vue'
5
5
// Use vue-resource package
6
6
Vue . use ( VueResource ) ;
7
7
8
- // Filters
9
- /*
10
- Vue.filter('to-uppercase', function(value){
11
- return value.toUpperCase();
12
- }); */
13
-
14
8
new Vue ( {
15
9
el : '#app' ,
16
10
render : h => h ( App )
Original file line number Diff line number Diff line change
1
+ export default {
2
+ computed : {
3
+ filteredBlogs : function ( ) {
4
+ return this . blogs . filter ( ( blog ) => {
5
+ return blog . title . match ( this . search ) ;
6
+ } ) ;
7
+ }
8
+ }
9
+ } ;
You can’t perform that action at this time.
0 commit comments