Skip to content

Commit 0a8003b

Browse files
authored
docs: translate api references > instance methods (#454)
1 parent 51f67ae commit 0a8003b

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

src/api/instance-methods.md

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## $watch
44

5-
- **Arguments:**
5+
- **引数:**
66

77
- `{string | Function} source`
88
- `{Function | Object} callback`
@@ -11,13 +11,13 @@
1111
- `{boolean} immediate`
1212
- `{string} flush`
1313

14-
- **Returns:** `{Function} unwatch`
14+
- **返り値:** `{Function} unwatch`
1515

16-
- **Usage:**
16+
- **使用方法:**
1717

18-
Watch a reactive property or a computed function on the component instance for changes. The callback gets called with the new value and the old value for the given property. We can only pass top-level `data`, `props`, or `computed` property name as a string. For more complex expressions or nested properties, use a function instead.
18+
コンポーネントインスタンスのリアクティブプロパティまたは算出関数(computed function)の変更を監視します。コールバックは指定されたプロパティの新しい値と古い値とともに呼び出されます。トップレベルの `data``props``computed` プロパティ名は文字列でしか渡すことができません。より複雑な式や、入れ子になったプロパティの場合は、代わりに関数を使います。
1919

20-
- **Example:**
20+
- **:**
2121

2222
```js
2323
const app = createApp({
@@ -32,34 +32,34 @@
3232
}
3333
},
3434
created() {
35-
// top-level property name
35+
// トップレベルのプロパティ名
3636
this.$watch('a', (newVal, oldVal) => {
37-
// do something
37+
// 何らかの処理
3838
})
3939

40-
// function for watching a single nested property
40+
// 1 つ入れ子になったプロパティを監視する関数
4141
this.$watch(
4242
() => this.c.d,
4343
(newVal, oldVal) => {
44-
// do something
44+
// 何らかの処理
4545
}
4646
)
4747

48-
// function for watching a complex expression
48+
// 複雑な式を監視する関数
4949
this.$watch(
50-
// every time the expression `this.a + this.b` yields a different result,
51-
// the handler will be called. It's as if we were watching a computed
52-
// property without defining the computed property itself
50+
// `this.a + this.b` という式が異なる結果を返すたびに、
51+
// ハンドラが呼び出されます。これはあたかも算出プロパティを定義することなしに
52+
// 算出プロパティを監視しているかのようです
5353
() => this.a + this.b,
5454
(newVal, oldVal) => {
55-
// do something
55+
// 何らかの処理
5656
}
5757
)
5858
}
5959
})
6060
```
6161

62-
When watched value is an object or array, any changes to its properties or elements won't trigger the watcher because they reference the same object/array:
62+
監視されている値がオブジェクトや配列の場合、それは同じオブジェクトや配列を参照しているため、どんな変更がそのプロパティや要素にあってもウォッチャは実行しません:
6363

6464
```js
6565
const app = createApp({
@@ -81,16 +81,16 @@
8181
})
8282
},
8383
methods: {
84-
// These methods won't trigger a watcher because we changed only a property of object/array,
85-
// not the object/array itself
84+
// これらのメソッドはオブジェクトや配列のプロパティを変更しただけで、
85+
// オブジェクトやプロパティ自体は変更していないため、ウォッチャを実行しません
8686
changeArticleText() {
8787
this.article.text = 'Vue 3 is awesome'
8888
},
8989
addComment() {
9090
this.comments.push('New comment')
9191
},
9292

93-
// These methods will trigger a watcher because we replaced object/array completely
93+
// これらのメソッドはオブジェクトや配列を完全に置き換えたため、ウォッチャを実行します
9494
changeWholeArticle() {
9595
this.article = { text: 'Vue 3 is awesome' }
9696
},
@@ -101,7 +101,7 @@
101101
})
102102
```
103103

104-
`$watch` returns an unwatch function that stops firing the callback:
104+
`$watch` はコールバックの実行を停止するアンウォッチ関数を返します:
105105

106106
```js
107107
const app = createApp({
@@ -115,39 +115,39 @@
115115
const vm = app.mount('#app')
116116

117117
const unwatch = vm.$watch('a', cb)
118-
// later, teardown the watcher
118+
// あとでウォッチャを解体
119119
unwatch()
120120
```
121121

122-
- **Option: deep**
122+
- **オプション: deep**
123123

124-
To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. This option also can be used to watch array mutations.
124+
オブジェクト内の入れ子になった値の変更も検出するには、オプション引数に `deep: true` を渡す必要があります。このオプションは配列のミューテートを監視するのにも使えます。
125125

126-
> Note: when mutating (rather than replacing) an Object or an Array and watch with deep option, the old value will be the same as new value because they reference the same Object/Array. Vue doesn't keep a copy of the pre-mutate value.
126+
> Note: オブジェクトや配列を(置き換えるのではなく)ミューテートさせて、deep オプションで監視した場合、古い値と新しい値は同じオブジェクトや配列を参照しているため、同じになります。Vue はミューテート前の値のコピーを保持しません。
127127
128128
```js
129129
vm.$watch('someObject', callback, {
130130
deep: true
131131
})
132132
vm.someObject.nestedValue = 123
133-
// callback is fired
133+
// コールバックを実行
134134
```
135135

136-
- **Option: immediate**
136+
- **オプション: immediate**
137137

138-
Passing in `immediate: true` in the option will trigger the callback immediately with the current value of the expression:
138+
オプションに `immediate: true` を渡すと、式の現在の値ですぐにコールバックを実行します:
139139

140140
```js
141141
vm.$watch('a', callback, {
142142
immediate: true
143143
})
144-
// `callback` is fired immediately with current value of `a`
144+
// `a` の現在の値ですぐに `callback` を実行
145145
```
146146

147-
Note that with `immediate` option you won't be able to unwatch the given property on the first callback call.
147+
`immediate` オプションをつけると、最初のコールバックの呼び出しでは与えられたプロパティをアンウォッチできないことに注意してください。
148148

149149
```js
150-
// This will cause an error
150+
// これはエラーが発生
151151
const unwatch = vm.$watch(
152152
'value',
153153
function() {
@@ -158,7 +158,7 @@
158158
)
159159
```
160160

161-
If you still want to call an unwatch function inside the callback, you should check its availability first:
161+
それでもコールバック内でアンウォッチ関数を呼び出したい場合、まずはその有効性を確認する必要があります:
162162

163163
```js
164164
let unwatch = null
@@ -175,38 +175,38 @@
175175
)
176176
```
177177

178-
- **Option: flush**
178+
- **オプション: flush**
179179

180-
The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`.
180+
`flush` オプションではコールバックのタイミングをより細かく制御することができます。これには `'pre'``'post'``'sync'` のいずれかを設定できます。
181181

182-
The default value is `'pre'`, which specifies that the callback should be invoked before rendering. This allows the callback to update other values before the template runs.
182+
デフォルト値は `'pre'` で、これはコールバックがレンダリングの前に呼び出されることを指定しています。これによりテンプレートの実行前にコールバックが他の値を更新することができます。
183183

184-
The value `'post'` can be used to defer the callback until after rendering. This should be used if the callback needs access to the updated DOM or child components via `$refs`.
184+
`'post'` の値はレンダリング後までコールバックを遅延させることができます。これはコールバックが更新された DOM や、`$refs` 経由で子コンポーネントにアクセスする必要がある場合に使います。
185185

186-
If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes.
186+
`flush` `'sync'` に設定された場合、コールバックは値が変更されるとすぐ非同期に呼び出されます。
187187

188-
For both `'pre'` and `'post'`, the callback is buffered using a queue. The callback will only be added to the queue once, even if the watched value changes multiple times. The interim values will be skipped and won't be passed to the callback.
188+
`'pre'` `'post'` のどちらもコールバックは、キューを使ってバッファリングされます。監視されている値が複数回変更されても、コールバックはキューに一度だけ追加されます。中間の値はスキップされて、コールバックには渡されません。
189189

190-
Buffering the callback not only improves performance but also helps to ensure data consistency. The watchers won't be triggered until the code performing the data updates has finished.
190+
コールバックのバッファリングはパフォーマンスの向上だけではなく、データの一貫性を確保するのにも役立ちます。ウォッチはデータの更新をするコードが完了するまで起動されません。
191191

192-
`'sync'` watchers should be used sparingly, as they don't have these benefits.
192+
`'sync'` ウォッチャは、これらの利点を持たないため、控えめに使う必要があります。
193193

194-
For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing).
194+
`flush` についての詳細な情報は [作用フラッシュのタイミング](../guide/reactivity-computed-watchers.html#作用フラッシュのタイミング) を参照してください。
195195

196-
- **See also:** [Watchers](../guide/computed.html#watchers)
196+
- **参照:** [ウォッチャ](../guide/computed.html#ウォッチャ)
197197

198198
## $emit
199199

200-
- **Arguments:**
200+
- **引数:**
201201

202202
- `{string} eventName`
203203
- `...args (optional)`
204204

205-
Trigger an event on the current instance. Any additional arguments will be passed into the listener's callback function.
205+
現在のインスタンスでイベントを発動します。追加の引数はリスナーのコールバック関数に渡されます。
206206

207-
- **Examples:**
207+
- **:**
208208

209-
Using `$emit` with only an event name:
209+
イベント名のみで `$emit` を使う:
210210

211211
```html
212212
<div id="emit-example-simple">
@@ -235,7 +235,7 @@
235235
app.mount('#emit-example-simple')
236236
```
237237

238-
Using `$emit` with additional arguments:
238+
追加の引数と `$emit` を使う:
239239

240240
```html
241241
<div id="emit-example-argument">
@@ -272,45 +272,45 @@
272272
app.mount('#emit-example-argument')
273273
```
274274

275-
- **See also:**
276-
- [`emits` option](./options-data.html#emits)
277-
- [Emitting a Value With an Event](../guide/component-basics.html#emitting-a-value-with-an-event)
275+
- **参照:**
276+
- [`emits` オプション](./options-data.html#emits)
277+
- [イベントと値を発行する](../guide/component-basics.html#イベントと値を発行する)
278278

279279
## $forceUpdate
280280

281-
- **Usage:**
281+
- **使用方法:**
282282

283-
Force the component instance to re-render. Note it does not affect all child components, only the instance itself and child components with inserted slot content.
283+
コンポーネントインスタンスの再レンダリングを強制します。これはすべての子コンポーネントには影響を与えず、インスタンスそれ自体とスロットのコンテンツが挿入された子コンポーネントにだけ影響します。
284284

285285
## $nextTick
286286

287-
- **Arguments:**
287+
- **引数:**
288288

289289
- `{Function} callback (optional)`
290290

291-
- **Usage:**
291+
- **使用方法:**
292292

293-
Defer the callback to be executed after the next DOM update cycle. Use it immediately after you've changed some data to wait for the DOM update. This is the same as the global `nextTick`, except that the callback's `this` context is automatically bound to the instance calling this method.
293+
次の DOM 更新サイクルの後に実行されるようコールバックを遅延します。なにかデータを変更したすぐ後に使って、DOM の更新を待ちます。これはコールバックの `this` コンテキストがこのメソッドを呼び出したインスタンスに自動的に束縛されることを除いて、グローバルの `nextTick` と同じです。
294294

295-
- **Example:**
295+
- **:**
296296

297297
```js
298298
createApp({
299299
// ...
300300
methods: {
301301
// ...
302302
example() {
303-
// modify data
303+
// データの変更
304304
this.message = 'changed'
305-
// DOM is not updated yet
305+
// DOM はまだ更新されていない
306306
this.$nextTick(function() {
307-
// DOM is now updated
308-
// `this` is bound to the current instance
307+
// DOM が更新される
308+
// `this` は現在のインスタンスに束縛される
309309
this.doSomethingElse()
310310
})
311311
}
312312
}
313313
})
314314
```
315315

316-
- **See also:** [nextTick](global-api.html#nexttick)
316+
- **参照:** [nextTick](global-api.html#nexttick)

0 commit comments

Comments
 (0)