Skip to content

Commit 96bf558

Browse files
author
Shaun Pelling
committed
added lesson 10 code
1 parent de9f0cd commit 96bf558

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

app.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
new Vue({
22
el: '#vue-app',
33
data: {
4-
a: 0,
5-
b: 0,
6-
age: 20
4+
available: false,
5+
nearby: false
76
},
87
methods: {
9-
/*addToA: function(){
10-
console.log('addToA');
11-
return this.a + this.age;
12-
},
13-
addToB: function(){
14-
console.log('addToB');
15-
return this.b + this.age;
16-
}*/
8+
179
},
1810
computed: {
19-
addToA: function(){
20-
console.log('addToA');
21-
return this.a + this.age;
22-
},
23-
addToB: function(){
24-
console.log('addToB');
25-
return this.b + this.age;
11+
compClasses: function(){
12+
return{
13+
available: this.available,
14+
nearby: this.nearby,
15+
}
2616
}
2717
}
2818
});

index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
</head>
99
<body>
1010
<div id="vue-app">
11-
<h1>Computed Properties</h1>
12-
<button v-on:click="a++">Add to A</button>
13-
<button v-on:click="b++">Add to B</button>
14-
<p>A - {{ a }}</p>
15-
<p>B - {{ b }}</p>
16-
<p>Age + A = {{ addToA }}</p>
17-
<p>Age + B = {{ addToB }}</p>
11+
<h1>Dynamic CSS</h1>
12+
<!-- <h2>Example 1</h2>
13+
<div v-on:click="available = !available" v-bind:class="{available: available}">
14+
<span>Ryu</span>
15+
</div> -->
16+
<h2>Example 2</h2>
17+
<button v-on:click="nearby = !nearby">Toggle nearby</button>
18+
<button v-on:click="available = !available">Toggle available</button>
19+
<div v-bind:class="compClasses">
20+
<span>Ryu</span>
21+
</div>
1822
</div>
1923
</body>
2024

styles.css

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
label{
2-
display: block;
3-
margin: 20px 0 10px
1+
span{
2+
background: red;
3+
display: inline-block;
4+
padding: 10px;
5+
color: #fff;
6+
margin: 10px 0;
7+
}
8+
9+
.available span{
10+
background: green;
11+
}
12+
13+
.nearby span:after{
14+
content: "nearby";
15+
margin-left: 10px;
416
}

0 commit comments

Comments
 (0)