You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 2.x, Vue instance could be used to trigger handlers attached imperatively via the event emitter API (`$on`, `$off` and `$once`). This was used to create _event hubs_ to create global event listeners used across the whole application:
14
+
2.x では、Vue インスタンスを使用して、イベントエミッタ API (`$on`、`$off`、`$once`) を介して強制的に接続されたハンドラをトリガすることができました。これは、アプリケーション全体で使用されるグローバルイベントリスナーを作成するための _イベントハブ_ を作るために使用されました。
15
15
16
16
```js
17
17
// eventHub.js
@@ -27,15 +27,15 @@ import eventHub from './eventHub'
27
27
28
28
exportdefault {
29
29
mounted() {
30
-
//adding eventHub listener
30
+
// eventHub リスナーの追加
31
31
eventHub.$on('custom-event', () => {
32
32
console.log('Custom event triggered!')
33
33
})
34
34
},
35
35
beforeDestroy() {
36
-
//removing eventHub listener
36
+
// eventHub リスナーの削除
37
37
eventHub.$off('custom-event')
38
-
}
38
+
},
39
39
}
40
40
```
41
41
@@ -46,18 +46,18 @@ import eventHub from './eventHub'
46
46
exportdefault {
47
47
methods: {
48
48
callGlobalCustomEvent() {
49
-
eventHub.$emit('custom-event') //if ChildComponent is mounted, we will have a message in the console
We removed `$on`, `$off` and `$once` methods from the instance completely. `$emit` is still a part of the existing API as it's used to trigger event handlers declaratively attached by a parent component
57
+
インスタンスから`$on`、`$off`、`$once`メソッドを完全に削除しました。`$emit`は、親コンポーネントによって宣言的にアタッチされたイベントハンドラをトリガするために使用されるので、まだ既存の API の一部です。
58
58
59
-
## Migration Strategy
59
+
## 移行の戦略
60
60
61
-
Existing event hubs can be replaced by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt).
0 commit comments