|
2 | 2 |
|
3 | 3 | ## data
|
4 | 4 |
|
5 |
| -- **Type:** `Function` |
| 5 | +- **型:** `Function` |
6 | 6 |
|
7 |
| -- **Details:** |
| 7 | +- **詳細:** |
8 | 8 |
|
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 プロパティのような独自のステートフルな振る舞いをするオブジェクトを監視することはお勧めしません。よい考え方としては、コンポーネントのデータを表すただのプレーンオブジェクトをここで持つべきです。 |
10 | 10 |
|
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 | + 一度監視されると、ルートのデータオブジェクトにリアクティブなプロパティを追加することはできなくなります。そのため、インスタンスを作成する前に、すべてのルートレベルのリアクティブプロパティを前もって宣言しておくことをお勧めします。 |
12 | 12 |
|
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` と同じになります。 |
14 | 14 |
|
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` としてアクセスする必要があります。 |
16 | 16 |
|
17 |
| -- **Example:** |
| 17 | +- **例:** |
18 | 18 |
|
19 | 19 | ```js
|
20 |
| - // direct instance creation |
| 20 | + // 直接インスタンスを生成 |
21 | 21 | const data = { a: 1 }
|
22 | 22 |
|
23 |
| - // The object is added to a component instance |
| 23 | + // コンポーネントインスタンスにオブジェクトを追加 |
24 | 24 | const vm = createApp({
|
25 | 25 | data() {
|
26 | 26 | return data
|
|
30 | 30 | console.log(vm.a) // => 1
|
31 | 31 | ```
|
32 | 32 |
|
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 引数としてそのインスタンスにアクセスできるということは忘れないでください。 |
34 | 34 |
|
35 | 35 | ```js
|
36 | 36 | data: vm => ({ a: vm.myProp })
|
37 | 37 | ```
|
38 | 38 |
|
39 |
| -- **See also:** [Reactivity in Depth](../guide/reactivity.html) |
| 39 | +- **参照:** [リアクティビティの探求](../guide/reactivity.html) |
40 | 40 |
|
41 | 41 | ## props
|
42 | 42 |
|
43 |
| -- **Type:** `Array<string> | Object` |
| 43 | +- **型:** `Array<string> | Object` |
44 | 44 |
|
45 |
| -- **Details:** |
| 45 | +- **詳細:** |
46 | 46 |
|
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 | + 親コンポーネントからデータを受け取るために公開されている属性のリストかハッシュです。配列ベースの単純な構文と、型チェックやカスタムバリデーション、デフォルト値などの高度な設定ができるオブジェクトベースの構文があります。 |
48 | 48 |
|
49 |
| - With Object-based syntax, you can use following options: |
| 49 | + オブジェクトベースの構文では、以下のオプションを使用できます: |
50 | 50 |
|
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#プロパティの型) を参照してください。 |
52 | 52 | - `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 | + プロパティのデフォルト値を指定します。プロパティが渡されない場合、この値が変わりに使用されます。オブジェクト、または配列のデフォルト値はファクトリ関数から返さなければなりません。 |
54 | 54 | - `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 ならプロパティが渡されない場合、コンソールに警告を出します。 |
56 | 56 | - `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#プロパティのバリデーション) を参照してください。 |
58 | 58 |
|
59 |
| -- **Example:** |
| 59 | +- **例:** |
60 | 60 |
|
61 | 61 | ```js
|
62 | 62 | const app = createApp({})
|
63 | 63 |
|
64 |
| - // simple syntax |
| 64 | + // 単純な構文 |
65 | 65 | app.component('props-demo-simple', {
|
66 | 66 | props: ['size', 'myMessage']
|
67 | 67 | })
|
68 | 68 |
|
69 |
| - // object syntax with validation |
| 69 | + // バリデーションありのオブジェクト構文 |
70 | 70 | app.component('props-demo-advanced', {
|
71 | 71 | props: {
|
72 |
| - // type check |
| 72 | + // 型チェック |
73 | 73 | height: Number,
|
74 |
| - // type check plus other validations |
| 74 | + // 型チェックと追加のバリデーション |
75 | 75 | age: {
|
76 | 76 | type: Number,
|
77 | 77 | default: 0,
|
|
84 | 84 | })
|
85 | 85 | ```
|
86 | 86 |
|
87 |
| -- **See also:** [Props](../guide/component-props.html) |
| 87 | +- **参照:** [プロパティ](../guide/component-props.html) |
88 | 88 |
|
89 | 89 | ## computed
|
90 | 90 |
|
91 |
| -- **Type:** `{ [key: string]: Function | { get: Function, set: Function } }` |
| 91 | +- **型:** `{ [key: string]: Function | { get: Function, set: Function } }` |
92 | 92 |
|
93 |
| -- **Details:** |
| 93 | +- **詳細:** |
94 | 94 |
|
95 |
| - Computed properties to be mixed into the component instance. All getters and setters have their `this` context automatically bound to the component instance. |
| 95 | + コンポーネントのインスタンスに混入される算出プロパティです。すべてのゲッターとセッターは、そのコンポーネントのインスタンスへ自動的に束縛される `this` コンテキストを持っています。 |
96 | 96 |
|
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 引数としてそのインスタンスにアクセスできるということは忘れないでください。: |
98 | 98 |
|
99 | 99 | ```js
|
100 | 100 | computed: {
|
101 | 101 | aDouble: vm => vm.a * 2
|
102 | 102 | }
|
103 | 103 | ```
|
104 | 104 |
|
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 | + 算出プロパティはキャッシュされ、リアクティブな依存の変更でのみ再計算されます。ある依存がインスタンスのスコープ外にある場合(例えばリアクティブでない場合)、算出プロパティは **更新されない** ことに注意してください。 |
106 | 106 |
|
107 |
| -- **Example:** |
| 107 | +- **例:** |
108 | 108 |
|
109 | 109 | ```js
|
110 | 110 | const app = createApp({
|
111 | 111 | data() {
|
112 | 112 | return { a: 1 }
|
113 | 113 | },
|
114 | 114 | computed: {
|
115 |
| - // get only |
| 115 | + // 取得のみ |
116 | 116 | aDouble() {
|
117 | 117 | return this.a * 2
|
118 | 118 | },
|
119 |
| - // both get and set |
| 119 | + // 取得と値の設定の両方 |
120 | 120 | aPlus: {
|
121 | 121 | get() {
|
122 | 122 | return this.a + 1
|
|
135 | 135 | console.log(vm.aDouble) // => 4
|
136 | 136 | ```
|
137 | 137 |
|
138 |
| -- **See also:** [Computed Properties](../guide/computed.html) |
| 138 | +- **参照:** [算出プロパティ](../guide/computed.html) |
139 | 139 |
|
140 | 140 | ## methods
|
141 | 141 |
|
142 |
| -- **Type:** `{ [key: string]: Function }` |
| 142 | +- **型:** `{ [key: string]: Function }` |
143 | 143 |
|
144 |
| -- **Details:** |
| 144 | +- **詳細:** |
145 | 145 |
|
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` コンテキストを持ちます。 |
147 | 147 |
|
148 | 148 | :::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` が未定義になるからです。 |
150 | 150 | :::
|
151 | 151 |
|
152 |
| -- **Example:** |
| 152 | +- **例:** |
153 | 153 |
|
154 | 154 | ```js
|
155 | 155 | const app = createApp({
|
|
169 | 169 | console.log(vm.a) // => 2
|
170 | 170 | ```
|
171 | 171 |
|
172 |
| -- **See also:** [Event Handling](../guide/events.html) |
| 172 | +- **参照:** [イベントハンドリング](../guide/events.html) |
173 | 173 |
|
174 | 174 | ## watch
|
175 | 175 |
|
176 |
| -- **Type:** `{ [key: string]: string | Function | Object | Array}` |
| 176 | +- **型:** `{ [key: string]: string | Function | Object | Array}` |
177 | 177 |
|
178 |
| -- **Details:** |
| 178 | +- **詳細:** |
179 | 179 |
|
180 |
| - An object where keys are reactive properties to watch — examples include [data](/api/options-data.html#data-2) or [computed](/api/options-data.html#computed) properties — 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. See [$watch](instance-methods.html#watch) for more information about the `deep`, `immediate` and `flush` options. |
| 180 | + キーが監視するリアクティブなプロパティで、例えば [data](/api/options-data.html#data-2) または [computed](/api/options-data.html#computed) プロパティを含み、値が対応するコールバックとなるオブジェクトです。値はメソッド名の文字列や、追加のオプションを含むオブジェクトを指定することもできます。コンポーネントインスタンスはインスタンス化の際に、オブジェクトの各エントリに対して `$watch()` を呼び出します。`deep`、`immediate`、または `flush` オプションの詳細については [$watch](instance-methods.html#watch) を参照してください。 |
181 | 181 |
|
182 |
| -- **Example:** |
| 182 | +- **例:** |
183 | 183 |
|
184 | 184 | ```js
|
185 | 185 | const app = createApp({
|
|
195 | 195 | }
|
196 | 196 | },
|
197 | 197 | watch: {
|
198 |
| - // watching top-level property |
| 198 | + // トップレベルのプロパティを監視 |
199 | 199 | a(val, oldVal) {
|
200 | 200 | console.log(`new: ${val}, old: ${oldVal}`)
|
201 | 201 | },
|
202 |
| - // string method name |
| 202 | + // メソッド名の文字列 |
203 | 203 | b: 'someMethod',
|
204 |
| - // the callback will be called whenever any of the watched object properties change regardless of their nested depth |
| 204 | + // 監視しているオブジェクトのプロパティが変更されると入れ子の深さに関わらずコールバックが呼び出されます |
205 | 205 | c: {
|
206 | 206 | handler(val, oldVal) {
|
207 | 207 | console.log('c changed')
|
208 | 208 | },
|
209 | 209 | deep: true
|
210 | 210 | },
|
211 |
| - // watching a single nested property: |
| 211 | + // 入れ子になった 1 つのプロパティを監視 |
212 | 212 | 'c.d': function (val, oldVal) {
|
213 | 213 | // do something
|
214 | 214 | },
|
215 |
| - // the callback will be called immediately after the start of the observation |
| 215 | + // 監視が開始した直後にコールバックが呼び出されます |
216 | 216 | e: {
|
217 | 217 | handler(val, oldVal) {
|
218 | 218 | console.log('e changed')
|
219 | 219 | },
|
220 | 220 | immediate: true
|
221 | 221 | },
|
222 |
| - // you can pass array of callbacks, they will be called one-by-one |
| 222 | + // コールバックの配列を渡せて、それらは 1 つずつ呼び出されます |
223 | 223 | f: [
|
224 | 224 | 'handle1',
|
225 | 225 | function handle2(val, oldVal) {
|
|
249 | 249 | ```
|
250 | 250 |
|
251 | 251 | ::: tip Note
|
252 |
| - 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` が未定義になるからです。 |
253 | 253 | :::
|
254 | 254 |
|
255 |
| -- **See also:** [Watchers](../guide/computed.html#watchers) |
| 255 | + |
| 256 | +- **参照:** [ウォッチャ](../guide/computed.html#ウォッチャ) |
256 | 257 |
|
257 | 258 | ## emits
|
258 | 259 |
|
259 |
| -- **Type:** `Array<string> | Object` |
| 260 | +- **型:** `Array<string> | Object` |
260 | 261 |
|
261 |
| -- **Details:** |
| 262 | +- **詳細:** |
262 | 263 |
|
263 |
| - 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 | + コンポーネントから発行されるカスタムイベントのリストやハッシュです。配列ベースの単純な構文と、イベントのバリデーションを設定できるオブジェクトベースの構文があります。 |
264 | 265 |
|
265 |
| - 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` を受け取ります。バリデーション関数は、イベントの引数が妥当かどうかを示すブール値を返す必要があります。 |
266 | 267 |
|
267 |
| -- **Usage:** |
| 268 | +- **使用方法:** |
268 | 269 |
|
269 | 270 | ```js
|
270 | 271 | const app = createApp({})
|
271 | 272 |
|
272 |
| - // Array syntax |
| 273 | + // 配列の構文 |
273 | 274 | app.component('todo-item', {
|
274 | 275 | emits: ['check'],
|
275 | 276 | created() {
|
276 | 277 | this.$emit('check')
|
277 | 278 | }
|
278 | 279 | })
|
279 | 280 |
|
280 |
| - // Object syntax |
| 281 | + // オブジェクトの構文 |
281 | 282 | app.component('reply-form', {
|
282 | 283 | emits: {
|
283 |
| - // no validation |
| 284 | + // バリデーションなし |
284 | 285 | click: null,
|
285 | 286 |
|
286 |
| - // with validation |
| 287 | + // バリデーションあり |
287 | 288 | submit: payload => {
|
288 | 289 | if (payload.email && payload.password) {
|
289 | 290 | return true
|
|
297 | 298 | ```
|
298 | 299 |
|
299 | 300 | ::: tip Note
|
300 |
| - 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` プロパティからも除外されます。 |
301 | 302 | :::
|
302 | 303 |
|
303 |
| -* **See also:** [Attribute Inheritance](../guide/component-attrs.html#attribute-inheritance) |
| 304 | +* **参照:** [属性の継承](../guide/component-attrs.html#属性の継承) |
0 commit comments