Skip to content

Commit 14aa9ab

Browse files
author
Shaun Pelling
committed
added lesson 34 code
1 parent 476cb4a commit 14aa9ab

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/components/showBlogs.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
2-
<div id="show-blogs">
2+
<div v-theme:column="'narrow'" id="show-blogs">
33
<h1>All Blog Articles</h1>
44
<div v-for="blog in blogs" class="single-blog">
5-
<h2>{{ blog.title }}</h2>
5+
<h2 v-rainbow>{{ blog.title }}</h2>
66
<article>{{ blog.body }}</article>
77
</div>
88
</div>

src/main.js

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

8+
// Custom directives
9+
Vue.directive('rainbow', {
10+
bind(el, binding, vnode){
11+
el.style.color = "#" + Math.random().toString(16).slice(2, 8);
12+
}
13+
});
14+
15+
Vue.directive('theme', {
16+
bind(el, binding, vnode){
17+
if (binding.value == 'wide'){
18+
el.style.maxWidth = "1260px";
19+
} else if (binding.value = 'narrow'){
20+
el.style.maxWidth = "560px";
21+
}
22+
if(binding.arg == 'column'){
23+
el.style.background = '#ddd';
24+
el.style.padding = '20px';
25+
}
26+
}
27+
});
28+
829
new Vue({
930
el: '#app',
1031
render: h => h(App)

0 commit comments

Comments
 (0)