File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Expand file tree Collapse file tree 2 files changed +26
-13
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
- name : '' ,
5
- age : ''
4
+ a : 0 ,
5
+ b : 0 ,
6
+ age : 20
6
7
} ,
7
8
methods : {
8
- logName : function ( ) {
9
- console . log ( 'you entered your name' ) ;
9
+ /*addToA: function(){
10
+ console.log('addToA');
11
+ return this.a + this.age;
10
12
},
11
- logAge : function ( ) {
12
- console . log ( 'you entered your age' ) ;
13
+ addToB: function(){
14
+ console.log('addToB');
15
+ return this.b + this.age;
16
+ }*/
17
+ } ,
18
+ 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 ;
13
26
}
14
27
}
15
28
} ) ;
Original file line number Diff line number Diff line change 8
8
</ head >
9
9
< body >
10
10
< div id ="vue-app ">
11
- < h1 > Keyboard Events </ h1 >
12
- < label > Name: </ label >
13
- < input type =" text " v-on:keyup.enter =" logName " v-model =" name " / >
14
- < span > {{ name }}</ span >
15
- < label > Age: </ label >
16
- < input type =" text " v-on:keyup.alt.enter =" logAge " v-model =" age " / >
17
- < span > {{ age }}</ span >
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 >
18
18
</ div >
19
19
</ body >
20
20
You can’t perform that action at this time.
0 commit comments