Skip to content

Commit 975a848

Browse files
committed
docs: translate guide/component-props.md
1 parent 032c9d5 commit 975a848

File tree

1 file changed

+70
-67
lines changed

1 file changed

+70
-67
lines changed

src/guide/component-props.md

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Props
1+
# プロパティ
22

3-
> This page assumes you've already read the [Components Basics](component-basics.md). Read that first if you are new to components.
3+
> このページは、すでに[コンポーネントの基本](component-basics.md)を読んだことを前提としています。コンポーネントに慣れていない場合は、まずはそちらをお読みください。
44
5-
## Prop Types
5+
## プロパティの型
66

7-
So far, we've only seen props listed as an array of strings:
7+
ここまでは、プロパティを文字列の配列として列挙してきました。
88

99
```js
1010
props: ['title', 'likes', 'isPublished', 'commentIds', 'author']
1111
```
1212

13-
Usually though, you'll want every prop to be a specific type of value. In these cases, you can list props as an object, where the properties' names and values contain the prop names and types, respectively:
13+
しかし、通常はすべてのプロパティを特定の型の値にしたいと思うでしょう。このような場合には、プロパティをオブジェクトとして列挙し、プロパティのキーと値にそれぞれプロパティの名前と型を設定します。
1414

1515
```js
1616
props: {
@@ -20,87 +20,88 @@ props: {
2020
commentIds: Array,
2121
author: Object,
2222
callback: Function,
23-
contactsPromise: Promise // or any other constructor
23+
contactsPromise: Promise // またはその他のコンストラクタ
2424
}
2525
```
2626

27-
This not only documents your component, but will also warn users in the browser's JavaScript console if they pass the wrong type. You'll learn much more about [type checks and other prop validations](#prop-validation) further down this page.
27+
こうすることでコンポーネントがドキュメント化されるだけでなく、間違った型を渡した場合に、ブラウザの JavaScript コンソールで警告の表示もされます。詳しくはこのページの下にある[プロパティのバリデーション](#プロパティのバリデーション) にて説明します。
2828

29-
## Passing Static or Dynamic Props
29+
## 静的あるいは動的なプロパティの受け渡し
3030

31-
So far, you've seen props passed a static value, like in:
31+
これまでは、このような形でプロパティが静的な値を渡しているところを見てきましたが:
3232

3333
```html
3434
<blog-post title="My journey with Vue"></blog-post>
3535
```
3636

37-
You've also seen props assigned dynamically with `v-bind` or its shortcut, the `:` character, such as in:
37+
次のような、`v-bind`やそのショートカットである `:` 文字を使って動的に割り当てられたプロパティも見たことがあるでしょう:
3838

3939
```html
40-
<!-- Dynamically assign the value of a variable -->
40+
<!-- 変数の値を動的に割り当てます -->
4141
<blog-post :title="post.title"></blog-post>
4242

43-
<!-- Dynamically assign the value of a complex expression -->
43+
<!-- 複数の変数を合成した値を動的に割り当てます -->
4444
<blog-post :title="post.title + ' by ' + post.author.name"></blog-post>
4545
```
4646

47-
In the two examples above, we happen to pass string values, but _any_ type of value can actually be passed to a prop.
47+
上の 2 つの例では、たまたま文字列の値を渡していますが、実際には __任意の__ 型の値をプロパティに渡すことができます。
4848

49-
### Passing a Number
49+
### 数値の受け渡し
5050

5151
```html
52-
<!-- Even though `42` is static, we need v-bind to tell Vue that -->
53-
<!-- this is a JavaScript expression rather than a string. -->
52+
<!-- `42` は静的な値ですが、これが文字列ではなく JavaScript の式だと -->
53+
<!-- Vue に伝えるためには v-bind を使う必要があります。 -->
5454
<blog-post :likes="42"></blog-post>
5555

56-
<!-- Dynamically assign to the value of a variable. -->
56+
<!-- 変数の値を動的に割り当てています。 -->
5757
<blog-post :likes="post.likes"></blog-post>
5858
```
5959

60-
### Passing a Boolean
60+
### 真偽値の受け渡し
6161

6262
```html
63-
<!-- Including the prop with no value will imply `true`. -->
63+
<!-- 値のないプロパティは、 `true` を意味します。 -->
6464
<blog-post is-published></blog-post>
6565

66-
<!-- Even though `false` is static, we need v-bind to tell Vue that -->
67-
<!-- this is a JavaScript expression rather than a string. -->
66+
<!-- `false` は静的な値ですが、これが文字列ではなく JavaScript の式だと -->
67+
<!-- Vue に伝えるには、 v-bind を使う必要があります。 -->
6868
<blog-post :is-published="false"></blog-post>
6969

70-
<!-- Dynamically assign to the value of a variable. -->
70+
<!-- 変数の値を動的に割り当てています。 -->
7171
<blog-post :is-published="post.isPublished"></blog-post>
7272
```
7373

74-
### Passing an Array
74+
### 配列の受け渡し
7575

7676
```html
77-
<!-- Even though the array is static, we need v-bind to tell Vue that -->
78-
<!-- this is a JavaScript expression rather than a string. -->
77+
<!-- この配列は静的ですが、これが文字列ではなく JavaScript の式だと -->
78+
<!-- Vue に伝えるには、 v-bind を使う必要があります。 -->
7979
<blog-post :comment-ids="[234, 266, 273]"></blog-post>
8080

81-
<!-- Dynamically assign to the value of a variable. -->
81+
<!-- 変数の値を動的に割り当てています。 -->
8282
<blog-post :comment-ids="post.commentIds"></blog-post>
8383
```
8484

85-
### Passing an Object
85+
### オブジェクトの受け渡し
8686

8787
```html
88-
<!-- Even though the object is static, we need v-bind to tell Vue that -->
89-
<!-- this is a JavaScript expression rather than a string. -->
88+
<!-- このオブジェクトは静的ですが、これが文字列ではなく JavaScript の式だと -->
89+
<!-- Vue に伝えるには、 v-bind を使う必要があります。 -->
9090
<blog-post
9191
:author="{
9292
name: 'Veronica',
9393
company: 'Veridian Dynamics'
9494
}"
9595
></blog-post>
9696

97-
<!-- Dynamically assign to the value of a variable. -->
97+
<!-- 変数の値を動的に割り当てています。 -->
9898
<blog-post :author="post.author"></blog-post>
9999
```
100100

101-
### Passing the Properties of an Object
101+
### オブジェクトのプロパティの受け渡し
102+
103+
オブジェクトのすべてのプロパティをコンポーネントのプロパティ(props)として渡したい場合は、引数なしで `v-bind` を使うことができます (`:prop-name` の代わりに `v-bind`を使用)。例えば、`post` オブジェクトが与えられたとします。
102104

103-
If you want to pass all the properties of an object as props, you can use `v-bind` without an argument (`v-bind` instead of `:prop-name`). For example, given a `post` object:
104105

105106
```js
106107
post: {
@@ -109,27 +110,27 @@ post: {
109110
}
110111
```
111112

112-
The following template:
113+
次のテンプレートは:
113114

114115
```html
115116
<blog-post v-bind="post"></blog-post>
116117
```
117118

118-
Will be equivalent to:
119+
以下と同等となります:
119120

120121
```html
121122
<blog-post v-bind:id="post.id" v-bind:title="post.title"></blog-post>
122123
```
123124

124-
## One-Way Data Flow
125+
## 単方向データフロー
125126

126-
All props form a **one-way-down binding** between the child property and the parent one: when the parent property updates, it will flow down to the child, but not the other way around. This prevents child components from accidentally mutating the parent's state, which can make your app's data flow harder to understand.
127+
すべてのプロパティは、子プロパティと親プロパティの間に **単方向のバインディング** を形成します: 親のプロパティが更新される場合は子へと流れ落ちますが、その逆はありません。これにより、子コンポーネントが誤って親の状態を変更すること(アプリのデータフローを理解しづらくすることがあります)を防ぎます。
127128

128-
In addition, every time the parent component is updated, all props in the child component will be refreshed with the latest value. This means you should **not** attempt to mutate a prop inside a child component. If you do, Vue will warn you in the console.
129+
さらに、親コンポーネントが更新されるたびに、子コンポーネントのすべてのプロパティは最新の値に更新されます。つまり、子コンポーネント内でプロパティの値を変化させては **いけません** 。変化させた場合、Vue はコンソールで警告を表示します。
129130

130-
There are usually two cases where it's tempting to mutate a prop:
131+
プロパティの値を変化させたい場合は主に 2 つあります:
131132

132-
1. **The prop is used to pass in an initial value; the child component wants to use it as a local data property afterwards.** In this case, it's best to define a local data property that uses the prop as its initial value:
133+
1. **プロパティを初期値として受け渡し、子コンポーネントにてローカルのデータとして後で利用したいと考える場合。** この場合は、プロパティの値を初期値として使うローカルの data プロパティを定義するのがベストです:
133134

134135
```js
135136
props: ['initialCounter'],
@@ -140,7 +141,7 @@ data() {
140141
}
141142
```
142143

143-
2. **The prop is passed in as a raw value that needs to be transformed.** In this case, it's best to define a computed property using the prop's value:
144+
2. **プロパティを変換が必要な未加工の値として受け渡す。** この場合、プロパティの値を使用した算出プロパティを別途定義するのがベストです:
144145

145146
```js
146147
props: ['size'],
@@ -152,52 +153,53 @@ computed: {
152153
```
153154

154155
::: tip Note
155-
Note that objects and arrays in JavaScript are passed by reference, so if the prop is an array or object, mutating the object or array itself inside the child component **will** affect parent state.
156+
JavaScript のオブジェクトと配列は、参照として渡されるため、子コンポーネント内で配列やオブジェクトを変更すると、 **親の状態に影響を与える** ことに注意してください。
156157
:::
157158

158-
## Prop Validation
159+
## プロパティのバリデーション
159160

160-
Components can specify requirements for their props, such as the types you've already seen. If a requirement isn't met, Vue will warn you in the browser's JavaScript console. This is especially useful when developing a component that's intended to be used by others.
161+
コンポーネントはプロパティに対して、すでに見たように型などの要件を指定することができます。要件が満たされていない場合、Vue はブラウザの JavaScript コンソールで警告を表示します。これは、他の人が使用することを意図したコンポーネントを開発する場合に特に便利です。
161162

162-
To specify prop validations, you can provide an object with validation requirements to the value of `props`, instead of an array of strings. For example:
163+
プロパティのバリデーションを指定するには、文字列の配列の代わりに、 `props` の値についてのバリデーション要件をもったオブジェクトを渡します。例えば以下のようなものです:
163164

164165
```js
165166
app.component('my-component', {
166167
props: {
167-
// Basic type check (`null` and `undefined` values will pass any type validation)
168+
// 基本的な型チェック (`null` `undefined` は全てのバリデーションをパスします)
168169
propA: Number,
169-
// Multiple possible types
170+
// 複数の型の許容
170171
propB: [String, Number],
171-
// Required string
172+
// 文字列型を必須で要求する
172173
propC: {
173174
type: String,
174175
required: true
175176
},
176-
// Number with a default value
177+
// デフォルト値つきの数値型
177178
propD: {
178179
type: Number,
179180
default: 100
180181
},
181-
// Object with a default value
182+
// デフォルト値つきのオブジェクト型
182183
propE: {
183184
type: Object,
184-
// Object or array defaults must be returned from
185-
// a factory function
185+
// オブジェクトもしくは配列のデフォルト値は
186+
// 必ずファクトリ関数(それを生み出すための関数)を返す必要があります。
186187
default: function() {
187188
return { message: 'hello' }
188189
}
189190
},
190-
// Custom validator function
191+
// カスタムバリデーション関数
191192
propF: {
192193
validator: function(value) {
193-
// The value must match one of these strings
194+
// プロパティの値は、必ずいずれかの文字列でなければならない
194195
return ['success', 'warning', 'danger'].indexOf(value) !== -1
195196
}
196197
},
197-
// Function with a default value
198+
// デフォルト値つきの関数型
198199
propG: {
199200
type: Function,
200-
// Unlike object or array default, this is not a factory function - this is a function to serve as a default value
201+
// オブジェクトや配列のデフォルトとは異なり、これはファクトリ関数ではありません。
202+
// これは、デフォルト値としての関数を取り扱います。
201203
default: function() {
202204
return 'Default function'
203205
}
@@ -206,15 +208,15 @@ app.component('my-component', {
206208
})
207209
```
208210

209-
When prop validation fails, Vue will produce a console warning (if using the development build).
211+
プロパティのバリデーションが失敗した場合、 Vue はコンソールに警告を表示します (開発用ビルドを利用しているとき)。
210212

211213
::: tip Note
212-
Note that props are validated **before** a component instance is created, so instance properties (e.g. `data`, `computed`, etc) will not be available inside `default` or `validator` functions.
214+
プロパティのバリデーションはコンポーネントのインスタンスが生成される **** に行われるため、インスタンスのプロパティ (例えば `data`, `computed` など) を `dafault` および `validator` 関数の中で利用することはできません。
213215
:::
214216

215-
### Type Checks
217+
### 型の検査
216218

217-
The `type` can be one of the following native constructors:
219+
`type` は、次のネイティブコンストラクタのいずれかです:
218220

219221
- String
220222
- Number
@@ -225,7 +227,7 @@ The `type` can be one of the following native constructors:
225227
- Function
226228
- Symbol
227229

228-
In addition, `type` can also be a custom constructor function and the assertion will be made with an `instanceof` check. For example, given the following constructor function exists:
230+
さらに、`type` はカスタムコンストラクタ関数であってもよく、アサーションは `instanceof` チェックにより行われます。例えば、以下のようなコンストラクタ関数が存在するとします:
229231

230232
```js
231233
function Person(firstName, lastName) {
@@ -234,7 +236,7 @@ function Person(firstName, lastName) {
234236
}
235237
```
236238

237-
You could use:
239+
このように利用することができます:
238240

239241
```js
240242
app.component('blog-post', {
@@ -244,25 +246,26 @@ app.component('blog-post', {
244246
})
245247
```
246248

247-
to validate that the value of the `author` prop was created with `new Person`.
249+
上の例では、 `author` プロパティの値が `new Person` によって作成されたものかどうか検証されます。
250+
251+
## プロパティの形式 (キャメルケース vs ケバブケース)
248252

249-
## Prop Casing (camelCase vs kebab-case)
253+
HTML の属性名は大文字小文字を区別しないので、ブラウザは全ての大文字を小文字として解釈します。つまり、 DOM(HTML) テンプレート内においては、キャメルケースのプロパティ名はケバブケース(ハイフンで区切ったもの)を使う必要があります。
250254

251-
HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you're using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents:
252255

253256
```js
254257
const app = Vue.createApp({})
255258

256259
app.component('blog-post', {
257-
// camelCase in JavaScript
260+
// JavaScript 内ではキャメルケース
258261
props: ['postTitle'],
259262
template: '<h3>{{ postTitle }}</h3>'
260263
})
261264
```
262265

263266
```html
264-
<!-- kebab-case in HTML -->
267+
<!-- HTML 内ではケバブケース -->
265268
<blog-post post-title="hello!"></blog-post>
266269
```
267270

268-
Again, if you're using string templates, this limitation does not apply.
271+
繰り返しになりますが、文字列テンプレートを使用している場合は、この制限は適用されません。

0 commit comments

Comments
 (0)