File tree 2 files changed +24
-6
lines changed
vuejs入门基础/my-second-vue-project/src
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 7
7
{{item.label}}
8
8
</li >
9
9
</ul >
10
- <component-a msgfromfather =' you die!' ></component-a >
10
+ <p >child tells me: {{childWords}} + {{childWordstow}}</p >
11
+ <component-a msgfromfather =' you die!' v-on:child-tell-me-something =' listenToMyBoy' ></component-a >
11
12
</div >
12
13
</template >
13
14
19
20
return {
20
21
title: ' this is a todo list' ,
21
22
items: Store .fetch (),
22
- newItem: ' '
23
+ newItem: ' ' ,
24
+ childWords: ' ' ,
25
+ childWordstow: ' '
23
26
};
24
27
},
25
28
components: {ComponentA},
31
34
deep: true
32
35
}
33
36
},
37
+ events: {
38
+ ' child-tell-me-something-two ' : function (msg ) {
39
+ this .childWordstow = msg;
40
+ }
41
+ },
34
42
methods: {
35
43
toggleFinish : function (item ) {
36
44
item .isFinished = ! item .isFinished ;
42
50
isFinished: false ,
43
51
});
44
52
this .newItem = ' ' ;
53
+ },
54
+ listenToMyBoy : function (msg ){
55
+ this .childWords = msg;
45
56
}
46
57
}
47
58
}
Original file line number Diff line number Diff line change 2
2
<div class =" hello" >
3
3
<h1 >{{ msg }}</h1 >
4
4
<h1 >{{msgfromfather}}</h1 >
5
- <button v-on:click =" onClickMe" >Click!</button >
5
+ <button v-on:click =" onClickMe" >open mouse!</button >
6
+ <button v-on:click =" onClickMetwo" >open mouse!</button >
6
7
</div >
7
8
</template >
8
9
9
10
<script >
10
11
export default {
11
12
data () {
12
13
return {
13
- msg: ' hello from component a!'
14
+ msg: ' hello from component a!' ,
15
+ msg1: ' dispatch msg'
14
16
}
15
17
},
16
18
props: [' msgfromfather' ],
17
19
methods: {
18
20
onClickMe : function (){
19
- console .log (this .msgfromfather );
20
- }
21
+ console .log (this .msgfromfather );
22
+ this .$emit (' child-tell-me-something' ,this .msg );
23
+ },
24
+ onClickMetwo : function (){
25
+ console .log (this .msgfromfather );
26
+ this .$dispatch (' child-tell-me-something-two' ,this .msg1 );
27
+ }
21
28
}
22
29
}
23
30
</script >
You can’t perform that action at this time.
0 commit comments