Skip to content

Commit 89259e3

Browse files
authored
API Reference > Options Data の翻訳を追従 (#395)
* docs: fix typo in options-data.md vuejs/docs@56eef72 * docs: add the flush option for $watch vuejs/docs@a09c316 * docs: reduce the reliance on the global Vue in API Reference examples vuejs/docs@35f5b52 * Added watching a nested property to API reference vuejs/docs@2106042 * Update options-data.md vuejs/docs@90688fa * docs: translate api reference > options > data
1 parent 1d7aa24 commit 89259e3

File tree

1 file changed

+75
-69
lines changed

1 file changed

+75
-69
lines changed

src/api/options-data.md

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
## data
44

5-
- **Type:** `Function`
5+
- **:** `Function`
66

7-
- **Details:**
7+
- **詳細:**
88

9-
The function that returns a data object for the component instance. In `data`, we don't recommend to observe objects with their own stateful behavior like browser API objects and prototype properties. A good idea would be to have here just a plain object that represents component data.
9+
コンポーネントインスタンスのデータオブジェクトを返す関数です。 `data` では、ブラウザの API オブジェクトや prototype プロパティのような独自のステートフルな振る舞いをするオブジェクトを監視することはお勧めしません。よい考え方としては、コンポーネントのデータを表すただのプレーンオブジェクトをここで持つべきです。
1010

11-
Once observed, you can no longer add reactive properties to the root data object. It is therefore recommended to declare all root-level reactive properties upfront, before creating the instance.
11+
一度監視されると、ルートのデータオブジェクトにリアクティブなプロパティを追加することはできなくなります。そのため、インスタンスを作成する前に、すべてのルートレベルのリアクティブプロパティを前もって宣言しておくことをお勧めします。
1212

13-
After the instance is created, the original data object can be accessed as `vm.$data`. The component instance also proxies all the properties found on the data object, so `vm.a` will be equivalent to `vm.$data.a`.
13+
インスタンスが作成された後に、`vm.$data` として元のデータオブジェクトアクセスできます。コンポーネントインスタンスは、データオブジェクトのすべてのプロパティをプロキシするため、`vm.a` `vm.$data.a` と同じになります。
1414

15-
Properties that start with `_` or `$` will **not** be proxied on the component instance because they may conflict with Vue's internal properties and API methods. You will have to access them as `vm.$data._property`.
15+
Vue の内部プロパティや API メソッドと競合する可能性があるため、`_` `$` からはじまるプロパティはコンポーネントインスタンスで **プロキシされません**。これらは `vm.$data._property` としてアクセスする必要があります。
1616

17-
- **Example:**
17+
- **:**
1818

1919
```js
20-
// direct instance creation
20+
// 直接インスタンスを生成
2121
const data = { a: 1 }
2222

23-
// The object is added to a component instance
24-
const vm = Vue.createApp({
23+
// コンポーネントインスタンスにオブジェクトを追加
24+
const vm = createApp({
2525
data() {
2626
return data
2727
}
@@ -30,48 +30,48 @@
3030
console.log(vm.a) // => 1
3131
```
3232

33-
Note that if you use an arrow function with the `data` property, `this` won't be the component's instance, but you can still access the instance as the function's first argument:
33+
`data` プロパティでアロー関数を使う場合、`this` はコンポーネントのインスタンスになりませんが、関数の第 1 引数としてそのインスタンスにアクセスできるということは忘れないでください。
3434

3535
```js
3636
data: vm => ({ a: vm.myProp })
3737
```
3838

39-
- **See also:** [Reactivity in Depth](../guide/reactivity.html)
39+
- **参照:** [リアクティビティの探求](../guide/reactivity.html)
4040

4141
## props
4242

43-
- **Type:** `Array<string> | Object`
43+
- **:** `Array<string> | Object`
4444

45-
- **Details:**
45+
- **詳細:**
4646

47-
A list/hash of attributes that are exposed to accept data from the parent component. It has an Array-based simple syntax and an alternative Object-based syntax that allows advanced configurations such as type checking, custom validation and default values.
47+
親コンポーネントからデータを受け取るために公開されている属性のリストかハッシュです。配列ベースの単純な構文と、型チェックやカスタムバリデーション、デフォルト値などの高度な設定ができるオブジェクトベースの構文があります。
4848

49-
With Object-based syntax, you can use following options:
49+
オブジェクトベースの構文では、以下のオプションを使用できます:
5050

51-
- `type`: can be one of the following native constructors: `String`, `Number`, `Boolean`, `Array`, `Object`, `Date`, `Function`, `Symbol`, any custom constructor function or an array of those. Will check if a prop has a given type, and will throw a warning if it doesn't. [More information](../guide/component-props.html#prop-types) on prop types.
51+
- `type`: 次のネイティブコンストラクタのいずれかになります: `String``Number``Boolean``Array``Object``Date``Function``Symbol`、任意のカスタムコンストラクタ関数、またはそれらの配列。プロパティが与えられた型を持っているか確認して、そうでない場合には警告を出します。プロパティの型について [詳細な情報](../guide/component-props.html#プロパティの型) を参照してください。
5252
- `default`: `any`
53-
Specifies a default value for the prop. If the prop is not passed, this value will be used instead. Object or array defaults must be returned from a factory function.
53+
プロパティのデフォルト値を指定します。プロパティが渡されない場合、この値が変わりに使用されます。オブジェクト、または配列のデフォルト値はファクトリ関数から返さなければなりません。
5454
- `required`: `Boolean`
55-
Defines if the prop is required. In a non-production environment, a console warning will be thrown if this value is truthy and the prop is not passed.
55+
プロパティが必須かどうかを定義します。非本番環境では、この値が true ならプロパティが渡されない場合、コンソールに警告を出します。
5656
- `validator`: `Function`
57-
Custom validator function that takes the prop value as the sole argument. In a non-production environment, a console warning will be thrown if this function returns a falsy value (i.e. the validation fails). You can read more about prop validation [here](../guide/component-props.html#prop-validation).
57+
プロパティの値を唯一の引数として受け取るカスタムバリデータ関数です。非本番環境では、この関数が false を返す場合(例えばバリデーションが失敗した場合)、コンソールに警告を出します。プロパティのバリデーションについて、詳しくは [こちら](../guide/component-props.html#プロパティのバリデーション) を参照してください。
5858

59-
- **Example:**
59+
- **:**
6060

6161
```js
62-
const app = Vue.createApp({})
62+
const app = createApp({})
6363

64-
// simple syntax
64+
// 単純な構文
6565
app.component('props-demo-simple', {
6666
props: ['size', 'myMessage']
6767
})
6868

69-
// object syntax with validation
69+
// バリデーションありのオブジェクト構文
7070
app.component('props-demo-advanced', {
7171
props: {
72-
// type check
72+
// 型チェック
7373
height: Number,
74-
// type check plus other validations
74+
// 型チェックと追加のバリデーション
7575
age: {
7676
type: Number,
7777
default: 0,
@@ -84,39 +84,39 @@
8484
})
8585
```
8686

87-
- **See also:** [Props](../guide/component-props.html)
87+
- **参照:** [プロパティ](../guide/component-props.html)
8888

8989
## computed
9090

91-
- **Type:** `{ [key: string]: Function | { get: Function, set: Function } }`
91+
- **:** `{ [key: string]: Function | { get: Function, set: Function } }`
9292

93-
- **Details:**
93+
- **詳細:**
9494

95-
Computed properties to be mixed into the Vcomponent instance. All getters and setters have their `this` context automatically bound to the component instance.
95+
コンポーネントのインスタンスに混入される算出プロパティです。すべてのゲッターとセッターは、そのコンポーネントのインスタンスへ自動的に束縛される `this` コンテキストを持っています。
9696

97-
Note that if you use an arrow function with a computed property, `this` won't be the component's instance, but you can still access the instance as the function's first argument:
97+
算出プロパティでアロー関数を使う場合、`this` はコンポーネントのインスタンスになりませんが、関数の第 1 引数としてそのインスタンスにアクセスできるということは忘れないでください。:
9898

9999
```js
100100
computed: {
101101
aDouble: vm => vm.a * 2
102102
}
103103
```
104104

105-
Computed properties are cached, and only re-computed on reactive dependency changes. Note that if a certain dependency is out of the instance's scope (i.e. not reactive), the computed property will **not** be updated.
105+
算出プロパティはキャッシュされ、リアクティブな依存の変更でのみ再計算されます。ある依存がインスタンスのスコープ外にある場合(例えばリアクティブでない場合)、算出プロパティは **更新されない** ことに注意してください。
106106

107-
- **Example:**
107+
- **:**
108108

109109
```js
110-
const app = Vue.createApp({
110+
const app = createApp({
111111
data() {
112112
return { a: 1 }
113113
},
114114
computed: {
115-
// get only
115+
// 取得のみ
116116
aDouble() {
117117
return this.a * 2
118118
},
119-
// both get and set
119+
// 取得と値の設定の両方
120120
aPlus: {
121121
get() {
122122
return this.a + 1
@@ -135,24 +135,24 @@
135135
console.log(vm.aDouble) // => 4
136136
```
137137

138-
- **See also:** [Computed Properties](../guide/computed.html)
138+
- **参照:** [算出プロパティ](../guide/computed.html)
139139

140140
## methods
141141

142-
- **Type:** `{ [key: string]: Function }`
142+
- **:** `{ [key: string]: Function }`
143143

144-
- **Details:**
144+
- **詳細:**
145145

146-
Methods to be mixed into the component instance. You can access these methods directly on the VM instance, or use them in directive expressions. All methods will have their `this` context automatically bound to the component instance.
146+
コンポーネントのインスタンスに混入されるメソッドです。これらのメソッドは、VM インスタンスで直接アクセスすることも、ディレクティブ式で使うこともできます。すべてのメソッドは、コンポーネントインスタンスに自動的に束縛された `this` コンテキストを持ちます。
147147

148148
:::tip Note
149-
Note that **you should not use an arrow function to define a method** (e.g. `plus: () => this.a++`). The reason is arrow functions bind the parent context, so `this` will not be the component instance as you expect and `this.a` will be undefined.
149+
**メソッドの定義にアロー関数を使ってはいけない** ということに注意してください(例: `plus: () => this.a++`)。その理由は、アロー関数が親のコンテキストを束縛するため、`this` が期待したとおりのコンポーネントインスタンスにならないのと、`this.a` が未定義になるからです。
150150
:::
151151

152-
- **Example:**
152+
- **:**
153153

154154
```js
155-
const app = Vue.createApp({
155+
const app = createApp({
156156
data() {
157157
return { a: 1 }
158158
},
@@ -169,52 +169,57 @@
169169
console.log(vm.a) // => 2
170170
```
171171

172-
- **See also:** [Event Handling](../guide/events.html)
172+
- **参照:** [イベントハンドリング](../guide/events.html)
173173

174174
## watch
175175

176-
- **Type:** `{ [key: string]: string | Function | Object | Array}`
176+
- **:** `{ [key: string]: string | Function | Object | Array}`
177177

178-
- **Details:**
178+
- **詳細:**
179179

180-
An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name, or an Object that contains additional options. The component instance will call `$watch()` for each entry in the object at instantiation.
180+
キーが監視するリアクティブなプロパティで、例えば [data](/api/options-data.html#data-2) または [computed](/api/options-data.html#computed) プロパティを含み、値が対応するコールバックとなるオブジェクトです。値はメソッド名の文字列や、追加のオプションを含むオブジェクトを指定することもできます。コンポーネントインスタンスはインスタンス化の際に、オブジェクトの各エントリに対して `$watch()` を呼び出します。`deep``immediate`、または `flush` オプションの詳細については [$watch](instance-methods.html#watch) を参照してください。
181181

182-
- **Example:**
182+
- **:**
183183

184184
```js
185-
const app = Vue.createApp({
185+
const app = createApp({
186186
data() {
187187
return {
188188
a: 1,
189189
b: 2,
190190
c: {
191191
d: 4
192192
},
193-
e: 'test',
194-
f: 5
193+
e: 5,
194+
f: 6
195195
}
196196
},
197197
watch: {
198+
// トップレベルのプロパティを監視
198199
a(val, oldVal) {
199200
console.log(`new: ${val}, old: ${oldVal}`)
200201
},
201-
// string method name
202+
// メソッド名の文字列
202203
b: 'someMethod',
203-
// the callback will be called whenever any of the watched object properties change regardless of their nested depth
204+
// 監視しているオブジェクトのプロパティが変更されると入れ子の深さに関わらずコールバックが呼び出されます
204205
c: {
205206
handler(val, oldVal) {
206207
console.log('c changed')
207208
},
208209
deep: true
209210
},
210-
// the callback will be called immediately after the start of the observation
211+
// 入れ子になった 1 つのプロパティを監視
212+
'c.d': function (val, oldVal) {
213+
// do something
214+
},
215+
// 監視が開始した直後にコールバックが呼び出されます
211216
e: {
212217
handler(val, oldVal) {
213218
console.log('e changed')
214219
},
215220
immediate: true
216221
},
217-
// you can pass array of callbacks, they will be called one-by-one
222+
// コールバックの配列を渡せて、それらは 1 つずつ呼び出されます
218223
f: [
219224
'handle1',
220225
function handle2(val, oldVal) {
@@ -244,41 +249,42 @@
244249
```
245250

246251
::: tip Note
247-
Note that _you should not use an arrow function to define a watcher_ (e.g. `searchQuery: newValue => this.updateAutocomplete(newValue)`). The reason is arrow functions bind the parent context, so `this` will not be the component instance as you expect and `this.updateAutocomplete` will be undefined.
252+
_ウォッチャの定義にアロー関数を使ってはいけない_ ということに注意してください(例: `searchQuery: newValue => this.updateAutocomplete(newValue)`)。その理由は、アロー関数が親のコンテキストを束縛するため、`this` は期待したとおりのコンポーネントインスタンスにはならないのと、`this.updateAutocomplete` が未定義になるからです。
248253
:::
249254

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

252258
## emits
253259

254-
- **Type:** `Array<string> | Object`
260+
- **:** `Array<string> | Object`
255261

256-
- **Details:**
262+
- **詳細:**
257263

258-
A list/hash of custom events that can be emitted from the component. It has an Array-based simple syntax and an alternative Object-based syntax that allows to configure an event validation.
264+
コンポーネントから発行されるカスタムイベントのリストやハッシュです。配列ベースの単純な構文と、イベントのバリデーションを設定できるオブジェクトベースの構文があります。
259265

260-
In Object-based syntax, the value of each property can either be `null` or a validator function. The validation function will receive the additional arguments passed to the `$emit` call. For example, if `this.$emit('foo', 1)` is called, the corresponding validator for `foo` will receive the argument `1`. The validator function should return a boolean to indicate whether the event arguments are valid.
266+
オブジェクトベースの構文では、各プロパティの値は `null` か、バリデーション関数のどちらかです。バリデーション関数は `$emit` の呼び出しに渡された追加の引数を受け取ります。例えば、`this.$emit('foo', 1)` が呼び出された場合、`foo` に対応するバリデータは、引数 `1` を受け取ります。バリデーション関数は、イベントの引数が妥当かどうかを示すブール値を返す必要があります。
261267

262-
- **Usage:**
268+
- **使用方法:**
263269

264270
```js
265-
const app = Vue.createApp({})
271+
const app = createApp({})
266272

267-
// Array syntax
273+
// 配列の構文
268274
app.component('todo-item', {
269275
emits: ['check'],
270276
created() {
271277
this.$emit('check')
272278
}
273279
})
274280

275-
// Object syntax
281+
// オブジェクトの構文
276282
app.component('reply-form', {
277283
emits: {
278-
// no validation
284+
// バリデーションなし
279285
click: null,
280286

281-
// with validation
287+
// バリデーションあり
282288
submit: payload => {
283289
if (payload.email && payload.password) {
284290
return true
@@ -292,7 +298,7 @@
292298
```
293299

294300
::: tip Note
295-
Events listed in the `emits` option **will not** be inherited by the root element of the component and also will be excluded from the `$attrs` property.
301+
`emits` オプションにリスト化されたイベントは、コンポーネントのルート要素には **継承されません**。また、`$attrs` プロパティからも除外されます。
296302
:::
297303

298-
* **See also:** [Attribute Inheritance](../guide/component-attrs.html#attribute-inheritance)
304+
* **参照:** [属性の継承](../guide/component-attrs.html#属性の継承)

0 commit comments

Comments
 (0)