Skip to content

Migration Guide > Events API の翻訳 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/guide/migration/events-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ badges:
- breaking
---

# Events API <MigrationBadges :badges="$frontmatter.badges" />
# イベント API <MigrationBadges :badges="$frontmatter.badges" />

## Overview
## 概要

`$on`, `$off` and `$once` instance methods are removed. Application instances no longer implement the event emitter interface.
インスタンスメソッド`$on``$off``$once`は削除されました。アプリケーションインスタンスはイベントエミッタインタフェースを実装しなくなりました。

## 2.x Syntax
## 2.x での構文

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:
2.x では、Vue インスタンスを使用して、イベントエミッタ API (`$on``$off``$once`) を介して強制的に接続されたハンドラをトリガすることができました。これは、アプリケーション全体で使用されるグローバルイベントリスナーを作成するための _イベントハブ_ を作るために使用されました。

```js
// eventHub.js
Expand All @@ -27,15 +27,15 @@ import eventHub from './eventHub'

export default {
mounted() {
// adding eventHub listener
// eventHub リスナーの追加
eventHub.$on('custom-event', () => {
console.log('Custom event triggered!')
})
},
beforeDestroy() {
// removing eventHub listener
// eventHub リスナーの削除
eventHub.$off('custom-event')
}
},
}
```

Expand All @@ -46,18 +46,18 @@ import eventHub from './eventHub'
export default {
methods: {
callGlobalCustomEvent() {
eventHub.$emit('custom-event') // if ChildComponent is mounted, we will have a message in the console
}
}
eventHub.$emit('custom-event') // ChildComponent がマウントされている場合、コンソールにメッセージが表示されます。
},
},
}
```

## 3.x Update
## 3.x での更新

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
インスタンスから`$on``$off``$once`メソッドを完全に削除しました。`$emit`は、親コンポーネントによって宣言的にアタッチされたイベントハンドラをトリガするために使用されるので、まだ既存の API の一部です。

## Migration Strategy
## 移行の戦略

Existing event hubs can be replaced by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt).
既存のイベントハブは、イベントエミッタインタフェースを実装した外部ライブラリ、例えば [mitt](https://github.com/developit/mitt) を使用して置き換えることができます。

These methods can also be supported in compatibility builds.
これらのメソッドは互換性のあるビルドでもサポートされています。