File tree Expand file tree Collapse file tree 3 files changed +34
-28
lines changed Expand file tree Collapse file tree 3 files changed +34
-28
lines changed Original file line number Diff line number Diff line change 1
1
new Vue ( {
2
2
el : '#vue-app' ,
3
3
data : {
4
- a : 0 ,
5
- b : 0 ,
6
- age : 20
4
+ available : false ,
5
+ nearby : false
7
6
} ,
8
7
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
+
17
9
} ,
18
10
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
+ }
26
16
}
27
17
}
28
18
} ) ;
Original file line number Diff line number Diff line change 8
8
</ head >
9
9
< body >
10
10
< 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 >
18
22
</ div >
19
23
</ body >
20
24
Original file line number Diff line number Diff line change 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 ;
4
16
}
You can’t perform that action at this time.
0 commit comments