Skip to content

Commit e53d0ec

Browse files
author
Shaun Pelling
committed
added lesson 38 code
1 parent 1b82e9d commit e53d0ec

File tree

5 files changed

+60
-33
lines changed

5 files changed

+60
-33
lines changed

src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<template>
22
<div>
33
<show-blogs></show-blogs>
4+
<list-blogs></list-blogs>
45
</div>
56
</template>
67

78
<script>
89
// Imports
910
import showBlogs from './components/showBlogs.vue';
11+
import listBlogs from './components/listBlogs.vue';
1012
1113
export default {
1214
components: {
13-
'show-blogs': showBlogs
15+
'show-blogs': showBlogs,
16+
'list-blogs': listBlogs
1417
},
1518
data () {
1619
return {

src/components/listBlogs.vue

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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>

src/components/showBlogs.vue

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,29 @@
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 v-rainbow>{{ blog.title | toUppercase }}</h2>
6+
<h2>{{ blog.title }}</h2>
77
<article>{{ blog.body }}</article>
88
</div>
99
</div>
1010
</template>
1111

1212
<script>
13+
// Imports
14+
import searchMixin from '../mixins/searchMixin';
15+
1316
export default {
1417
data () {
1518
return {
1619
blogs: [],
1720
search: ''
1821
}
19-
},
20-
methods: {
21-
2222
},
2323
created() {
2424
this.$http.get('http://jsonplaceholder.typicode.com/posts').then(function(data){
2525
this.blogs = data.body.slice(0,10);
2626
});
2727
},
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]
5029
}
5130
</script>
5231

src/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import App from './App.vue'
55
// Use vue-resource package
66
Vue.use(VueResource);
77

8-
// Filters
9-
/*
10-
Vue.filter('to-uppercase', function(value){
11-
return value.toUpperCase();
12-
}); */
13-
148
new Vue({
159
el: '#app',
1610
render: h => h(App)

src/mixins/searchMixin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
};

0 commit comments

Comments
 (0)