@@ -31,7 +31,7 @@ EventBus.$emit('message', 'hello world');
31
31
``` javascript
32
32
// 이벤트 구독
33
33
EventBus .$on (' message' , function (text ) {
34
- console .log (text);
34
+ console .log (text);
35
35
});
36
36
```
37
37
@@ -43,23 +43,23 @@ EventBus.$on('message', function(text) {
43
43
44
44
``` xml
45
45
<div id =" sender-app" >
46
- <input v-model =" text" >
47
- <button @click=" sender" >sender</button >
46
+ <input v-model =" text" >
47
+ <button @click=" sender" >sender</button >
48
48
<div v-if =" receiveText" >#sender-app: I sent a message a {{ receiveText }}</div >
49
49
</div >
50
50
<div id =" receiver-app" >
51
- <div v-if =" text" >#receiver-app: {{ text }}</div >
51
+ <div v-if =" text" >#receiver-app: {{ text }}</div >
52
52
</div >
53
53
```
54
54
55
55
``` javascript
56
56
var EventBus = new Vue ();
57
57
58
58
var SenderApp = new Vue ({
59
- el: ' #sender-app' ,
59
+ el: ' #sender-app' ,
60
60
data () {
61
61
return {
62
- text: ' ' ,
62
+ text: ' ' ,
63
63
receiveText: ' '
64
64
}
65
65
},
@@ -68,28 +68,28 @@ var SenderApp = new Vue({
68
68
},
69
69
methods: {
70
70
sender () {
71
- EventBus .$emit (' message' , this .text );
71
+ EventBus .$emit (' message' , this .text );
72
72
this .text = ' ' ;
73
73
},
74
74
onReceive (text ) {
75
- this .receiveText = text;
75
+ this .receiveText = text;
76
76
}
77
77
}
78
78
});
79
79
80
80
var ReceiverApp = new Vue ({
81
- el: ' #receiver-app' ,
81
+ el: ' #receiver-app' ,
82
82
data () {
83
83
return {
84
- text: ' '
84
+ text: ' '
85
85
}
86
86
},
87
- created () {
87
+ created () {
88
88
EventBus .$on (' message' , this .onReceive );
89
89
},
90
90
methods: {
91
91
onReceive (text ) {
92
- this .text = text;
92
+ this .text = text;
93
93
}
94
94
}
95
95
});
@@ -102,7 +102,7 @@ var ReceiverApp = new Vue({
102
102
``` javascript
103
103
(function () {
104
104
105
- var EventBus = Vue ();
105
+ var EventBus = Vue ();
106
106
107
107
Object .defineProperties (Vue .prototype , {
108
108
$eventBus: {
@@ -121,4 +121,4 @@ var ReceiverApp = new Vue({
121
121
- [vue.js 공식홈페이지 - 비-부모-자식간-통신](https://kr.vuejs.org/v2/guide/components.html#비-부모-자식간-통신)
122
122
- [Building a Simple Event Bus in Vue.js - Arvid Kahl](https://devblog.digimondo.io/building-a-simple-eventbus-in-vue-js-64b70fb90834#.ksf302nhz)
123
123
- [vue.js 한국어 사용자 모임](https://vuejs-kr.github.io/)
124
- - [진블로그 - Vuejs EventBus](http://blog.puding.kr/179)
124
+ - [진블로그 - Vuejs EventBus](http://blog.puding.kr/179)
0 commit comments