Skip to content

Commit 61afc33

Browse files
naokiekazupon
andauthored
API Reference > Options > Lifecycle Hooks の翻訳 (#460)
* docs: translate api reference > options > lifecycle hooks * fix: the translation of 'patch' Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com> * fix: corrected the translation of 'patch' Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com> * fix: supplement for kept-alive component Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com>
1 parent 275b0fc commit 61afc33

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed

src/api/options-lifecycle-hooks.md

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,182 @@
1-
# Lifecycle hooks
1+
# ライフサイクルフック
22

33
:::tip Note
4-
All lifecycle hooks automatically have their `this` context bound to the instance, so that you can access data, computed properties, and methods. This means **you should not use an arrow function to define a lifecycle method** (e.g. `created: () => this.fetchTodos()`). The reason is arrow functions bind the parent context, so `this` will not be the component instance as you expect and `this.fetchTodos` will be undefined.
4+
すべてのライフライクルフックは、自動的にその `this` コンテキストをインスタンスに束縛するため、データ、算出プロパティ、およびメソッドにアクセスできます。これはつまり、**ライフサイクルメソッドの定義にアロー関数を使ってはいけない** ということです(例: `created: () => this.fetchTodos()`)。その理由は、アロー関数が親のコンテキストを束縛するためで、`this` が期待した通りのコンポーネントインスタンスをにならず、`this.fetchTodos` undefined になるからです。
55
:::
66

77
## beforeCreate
88

9-
- **Type:** `Function`
9+
- **:** `Function`
1010

11-
- **Details:**
11+
- **詳細:**
1212

13-
Called synchronously immediately after the instance has been initialized, before data observation and event/watcher setup.
13+
インスタンスが初期化された直後、データの監視とイベント/ウォッチャの設定前に、同期的に呼び出されます。
1414

15-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
15+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
1616

1717
## created
1818

19-
- **Type:** `Function`
19+
- **:** `Function`
2020

21-
- **Details:**
21+
- **詳細:**
2222

23-
Called synchronously after the instance is created. At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, the mounting phase has not been started, and the `$el` property will not be available yet.
23+
インスタンスが作成された後に、同期的に呼び出されます。この段階では、インスタンスはオプションの処理を終えています。つまり、次のものが設定されています: データの監視、算出プロパティ、メソッド、ウォッチ/イベントのコールバック。しかし、マウントのフェーズは始まっていないので、`$el` プロパティはまだ利用できません。
2424

25-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
25+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
2626

2727
## beforeMount
2828

29-
- **Type:** `Function`
29+
- **:** `Function`
3030

31-
- **Details:**
31+
- **詳細:**
3232

33-
Called right before the mounting begins: the `render` function is about to be called for the first time.
33+
マウントがはじまる直前に呼び出されます: `render` 関数が初めて呼び出されるところです。
3434

35-
**This hook is not called during server-side rendering.**
35+
**このフックはサーバサイドレンダリングで呼び出されません。**
3636

37-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
37+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
3838

3939
## mounted
4040

41-
- **Type:** `Function`
41+
- **:** `Function`
4242

43-
- **Details:**
43+
- **詳細:**
4444

45-
Called after the instance has been mounted, where element, passed to [`app.mount`](/api/application-api.html#mount) is replaced by the newly created `vm.$el`. If the root instance is mounted to an in-document element, `vm.$el` will also be in-document when `mounted` is called.
45+
インスタンスがマウントされた後に呼び出され、[`app.mount`](/api/application-api.html#mount) に渡された要素は、その新しく作成された `vm.$el` で置き換えられます。ルートインスタンスがドキュメントの中の要素にマウントされた場合、`mounted` が呼び出されたときに、`vm.$el` もドキュメントに配置されます。
4646

47-
Note that `mounted` does **not** guarantee that all child components have also been mounted. If you want to wait until the entire view has been rendered, you can use [vm.$nextTick](../api/instance-methods.html#nexttick) inside of `mounted`:
47+
`mounted` は、すべての子コンポーネントもマウントされていることを **保証しない** ことに注意してください。ビュー全体がレンダリングされるまで待ちたい場合は、`mounted` の代わりに [vm.$nextTick](../api/instance-methods.html#nexttick) を使うことができます:
4848

4949
```js
5050
mounted() {
5151
this.$nextTick(function () {
52-
// Code that will run only after the
53-
// entire view has been rendered
52+
// ビュー全体がレンダリングされた後にのみ
53+
// 実行されるコード
5454
})
5555
}
5656
```
5757

58-
**This hook is not called during server-side rendering.**
58+
**このフックはサーバサイドレンダリングで呼び出されません。**
5959

60-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
60+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
6161

6262
## beforeUpdate
6363

64-
- **Type:** `Function`
64+
- **:** `Function`
6565

66-
- **Details:**
66+
- **詳細:**
6767

68-
Called when data changes, before the DOM is patched. This is a good place to access the existing DOM before an update, e.g. to remove manually added event listeners.
68+
データが変更されるとき、DOM に patch (Virtual DOM の処理プロセス)される前に呼び出されます。これは例えば、手動で追加されたイベントリスナを削除するといった、更新前に既存の DOM にアクセスするのに適しています。
6969

70-
**This hook is not called during server-side rendering, because only the initial render is performed server-side.**
70+
**このフックはサーバサイドレンダリングで呼び出されません。初期レンダリングのみ実行されるためです。**
7171

72-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
72+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
7373

7474
## updated
7575

76-
- **Type:** `Function`
76+
- **:** `Function`
7777

78-
- **Details:**
78+
- **詳細:**
7979

80-
Called after a data change causes the virtual DOM to be re-rendered and patched.
80+
データの変更後に仮想 DOM が再レンダリングされ、patch が適用された後に呼び出されます。
8181

82-
The component's DOM will have been updated when this hook is called, so you can perform DOM-dependent operations here. However, in most cases you should avoid changing state inside the hook. To react to state changes, it's usually better to use a [computed property](./options-data.html#computed) or [watcher](./options-data.html#watch) instead.
82+
このフックが呼び出されたときには、コンポーネントの DOM は更新されているので、ここで DOM に依存した操作を行うことができます。しかしほとんどの場合、フックの中で状態を変更することは避けるべきです。状態を変更するためには、通常代わりに [算出プロパティ](./options-data.html#computed) [ウォッチャ](./options-data.html#watch) を使うほうがよいでしょう。
8383

84-
Note that `updated` does **not** guarantee that all child components have also been re-rendered. If you want to wait until the entire view has been re-rendered, you can use [vm.$nextTick](../api/instance-methods.html#nexttick) inside of `updated`:
84+
`updated` は、すべての子コンポーネントが再レンダリングされたことを保証するものでは **ありません**。ビュー全体が再レンダリングされるまで待ちたいなら、[vm.$nextTick](../api/instance-methods.html#nexttick) `updated` の中で使うことができます:
8585

8686
```js
8787
updated() {
8888
this.$nextTick(function () {
89-
// Code that will run only after the
90-
// entire view has been re-rendered
89+
// ビュー全体が再レンダリングされた後にのみ
90+
// 実行されるコード
9191
})
9292
}
9393
```
9494

95-
**This hook is not called during server-side rendering.**
95+
**このフックはサーバサイドレンダリングで呼び出されません。**
9696

97-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
97+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
9898

9999
## activated
100100

101-
- **Type:** `Function`
101+
- **:** `Function`
102102

103-
- **Details:**
103+
- **詳細:**
104104

105-
Called when a kept-alive component is activated.
105+
kept-alive コンポーネント(keep-alive が内部で保持する子コンポーネント)がアクティブになったときに呼び出されます。
106106

107-
**This hook is not called during server-side rendering.**
107+
**このフックはサーバサイドレンダリングで呼び出されません。**
108108

109-
- **See also:**
110-
- [Dynamic Components - keep-alive](../guide/component-dynamic-async.html#dynamic-components-with-keep-alive)
109+
- **参照:**
110+
- [動的コンポーネント - keep-alive](../guide/component-dynamic-async.html#動的コンポーネントにおける-keep-alive-の利用)
111111

112112
## deactivated
113113

114-
- **Type:** `Function`
114+
- **:** `Function`
115115

116-
- **Details:**
116+
- **詳細:**
117117

118-
Called when a kept-alive component is deactivated.
118+
kept-alive コンポーネント(keep-alive が内部で保持する子コンポーネント)が非アクティブになったときに呼び出されます。
119119

120-
**This hook is not called during server-side rendering.**
120+
**このフックはサーバサイドレンダリングで呼び出されません。**
121121

122-
- **See also:**
123-
- [Dynamic Components - keep-alive](../guide/component-dynamic-async.html#dynamic-components-with-keep-alive)
122+
- **参照:**
123+
- [動的コンポーネント - keep-alive](../guide/component-dynamic-async.html#動的コンポーネントにおける-keep-alive-の利用)
124124

125125
## beforeUnmount
126126

127-
- **Type:** `Function`
127+
- **:** `Function`
128128

129-
- **Details:**
129+
- **詳細:**
130130

131-
Called right before a component instance is unmounted. At this stage the instance is still fully functional.
131+
コンポーネントインスタンスがアンマウントされる直前に呼び出されます。この段階ではインスタンスはまだ完全に機能しています。
132132

133-
**This hook is not called during server-side rendering.**
133+
**このフックはサーバサイドレンダリングで呼び出されません。**
134134

135-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
135+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
136136

137137
## unmounted
138138

139-
- **Type:** `Function`
139+
- **:** `Function`
140140

141-
- **Details:**
141+
- **詳細:**
142142

143-
Called after a component instance has been unmounted. When this hook is called, all directives of the component instance have been unbound, all event listeners have been removed, and all child component instance have also been unmounted.
143+
コンポーネントインスタンスがアンマウントされた後に呼び出されます。このフックが呼び出されたときには、コンポーネントインスタンスのすべてのディレクティブはバインド解除され、すべてのイベントリスナは削除され、すべての子コンポーネントインスタンスもアンマウントされています。
144144

145-
**This hook is not called during server-side rendering.**
145+
**このフックはサーバサイドレンダリングで呼び出されません。**
146146

147-
- **See also:** [Lifecycle Diagram](../guide/instance.html#lifecycle-diagram)
147+
- **参照:** [ライフサイクルダイアグラム](../guide/instance.html#ライフサイクルダイアグラム)
148148

149149
## errorCaptured
150150

151-
- **Type:** `(err: Error, instance: Component, info: string) => ?boolean`
151+
- **:** `(err: Error, instance: Component, info: string) => ?boolean`
152152

153-
- **Details:**
153+
- **詳細:**
154154

155-
Called when an error from any descendent component is captured. The hook receives three arguments: the error, the component instance that triggered the error, and a string containing information on where the error was captured. The hook can return `false` to stop the error from propagating further.
155+
任意の子孫コンポーネントからエラーが捕捉されたときに呼び出されます。このフックは 3 つの引数を受け取ります: エラーと、エラーを引き起こしたコンポーネントインスタンスと、エラーが捕捉された箇所の情報を含む文字列です。このフックは更にエラーが伝播するのを防ぐために、`false` を返すことができます。
156156

157157
:::tip
158-
You can modify component state in this hook. However, it is important to have conditionals in your template or render function that short circuits other content when an error has been captured; otherwise the component will be thrown into an infinite render loop.
158+
このフックでコンポーネントの状態を変更することができます。しかし、テンプレートや Render 関数でエラーが捕捉されたときに、他のコンテンツを手短に迂回させるような条件分岐を用意することが重要です。そうでなければ、コンポーネントは無限のレンダリングループに陥ってしまいます。
159159
:::
160160

161-
**Error Propagation Rules**
161+
**エラー伝播のルール**
162162

163-
- By default, all errors are still sent to the global `config.errorHandler` if it is defined, so that these errors can still be reported to an analytics service in a single place.
163+
- デフォルトでは、グローバルの `config.errorHandler` が定義されている場合、すべてのエラーが送信されます。そのため、これらのエラーを単一の場所でアナリティクスサービスに報告することができます。
164164

165-
- If multiple `errorCaptured` hooks exist on a component's inheritance chain or parent chain, all of them will be invoked on the same error.
165+
- もし複数の `errorCaptured` フックがコンポーネントの継承チェーンや親チェーンに存在する場合、それらすべては同じエラーで呼び出されます。
166166

167-
- If the `errorCaptured` hook itself throws an error, both this error and the original captured error are sent to the global `config.errorHandler`.
167+
- もし `errorCaptured` フック自身がエラーを投げると、このエラーと元のキャプチャされたエラーの両方がグローバルの `config.errorHandler` に送られます。
168168

169-
- An `errorCaptured` hook can return `false` to prevent the error from propagating further. This is essentially saying "this error has been handled and should be ignored." It will prevent any additional `errorCaptured` hooks or the global `config.errorHandler` from being invoked for this error.
169+
- `errorCaptured` フックは、エラーがさらに伝播するのを防ぐために `false` を返すことができます。これは本質的に「このエラーは処理済みなので、無視する必要がある」と言うことです。このエラーについて、追加の `errorCaptured` フックや、グローバルの `config.errorHandler` が呼び出されることを防ぎます。
170170

171171
## renderTracked
172172

173-
- **Type:** `(e: DebuggerEvent) => void`
173+
- **:** `(e: DebuggerEvent) => void`
174174

175-
- **Details:**
175+
- **詳細:**
176176

177-
Called when virtual DOM re-render is tracked. The hook receives a `debugger event` as an argument. This event tells you what operation tracked the component and the target object and key of that operation.
177+
仮想 DOM の再レンダリングが追跡されたときに呼び出されます。このフックは引数として `debugger event` を受け取ります。このイベントは、どの操作がコンポーネントを追跡したのか、その操作のターゲットオブジェクトとキーを教えてくれます。
178178

179-
- **Usage:**
179+
- **使用方法:**
180180

181181
```html
182182
<div id="app">
@@ -194,7 +194,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
194194
},
195195
renderTracked({ key, target, type }) {
196196
console.log({ key, target, type })
197-
/* This will be logged when component is rendered for the first time:
197+
/* これはコンポーネントの初回レンダリングに記録されます:
198198
{
199199
key: "cart",
200200
target: {
@@ -216,13 +216,13 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
216216

217217
## renderTriggered
218218

219-
- **Type:** `(e: DebuggerEvent) => void`
219+
- **:** `(e: DebuggerEvent) => void`
220220

221-
- **Details:**
221+
- **詳細:**
222222

223-
Called when virtual DOM re-render is triggered. Similarly to [`renderTracked`](#rendertracked), receives a `debugger event` as an argument. This event tells you what operation triggered the re-rendering and the target object and key of that operation.
223+
仮想 DOM の再レンダリングが実行されたときに呼び出されます。[`renderTracked`](#rendertracked) と同様に、引数として `debugger event` を受け取ります。このイベントは、どの操作が再レンダリングのきっかけとなったか、その操作のターゲットオブジェクトとキーを教えてくれます。
224224

225-
- **Usage:**
225+
- **使用方法:**
226226

227227
```html
228228
<div id="app">
@@ -244,7 +244,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
244244
methods: {
245245
addToCart() {
246246
this.cart += 1
247-
/* This will cause renderTriggered call
247+
/* これにより renderTriggered を呼び出します
248248
{
249249
key: "cart",
250250
target: {

0 commit comments

Comments
 (0)