Skip to content

Commit 26587b0

Browse files
authored
docs: Essentials > List Rendering の翻訳 #8 (#92)
* docs:translate guide/list.md * fix translate guide/list.md
1 parent 9aac71b commit 26587b0

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

src/guide/list.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# List Rendering
1+
# リストレンダリング
22

3-
## Mapping an Array to Elements with `v-for`
3+
## v-for で配列に要素をマッピングする
44

5-
We can use the `v-for` directive to render a list of items based on an array. The `v-for` directive requires a special syntax in the form of `item in items`, where `items` is the source data array and `item` is an **alias** for the array element being iterated on:
5+
配列に基づいて、アイテムのリストを描画するために、`v-for` ディレクティブを使用することができます。 `v-for` ディレクティブには、 `item in items` の形式の特別な構文が必要で、 `items` はソースデータの配列、 `item` は繰り返される配列要素の**エイリアス**です:
66

77
```html
88
<ul id="array-rendering">
@@ -22,7 +22,7 @@ Vue.createApp({
2222
}).mount('#array-rendering')
2323
```
2424

25-
Result:
25+
結果:
2626

2727
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="js,result" data-user="Vue" data-slug-hash="VwLGbwa" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="v-for with Array">
2828
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/VwLGbwa">
@@ -31,7 +31,7 @@ Result:
3131
</p>
3232
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
3333

34-
Inside `v-for` blocks we have full access to parent scope properties. `v-for` also supports an optional second argument for the index of the current item.
34+
`v-for` ブロック内では、親スコープのプロパティへの完全なアクセスを持っています。また `v-for` は現在のアイテムに対する配列のインデックスを、任意の2つ目の引数としてサポートしています。
3535

3636
```html
3737
<ul id="array-with-index">
@@ -52,7 +52,7 @@ Vue.createApp({
5252
}).mount('#array-with-index')
5353
```
5454

55-
Result:
55+
結果:
5656

5757
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="js,result" data-user="Vue" data-slug-hash="wvaEdBP" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="v-for with Array and index">
5858
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/wvaEdBP">
@@ -61,15 +61,15 @@ Result:
6161
</p>
6262
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
6363

64-
You can also use `of` as the delimiter instead of `in`, so that it is closer to JavaScript's syntax for iterators:
64+
また、区切り文字として `in` の代わりに `of` を使用することができます。これは JavaScript のイテレータ構文に近いものです:
6565

6666
```html
6767
<div v-for="item of items"></div>
6868
```
6969

70-
## `v-for` with an Object
70+
## オブジェクトの `v-for`
7171

72-
You can also use `v-for` to iterate through the properties of an object.
72+
オブジェクトのプロパティに対して、`v-for` を使って反復処理することもできます。
7373

7474
```html
7575
<ul id="v-for-object" class="demo">
@@ -93,7 +93,7 @@ Vue.createApp({
9393
}).mount('#v-for-object')
9494
```
9595

96-
Result:
96+
結果:
9797

9898
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="js,result" data-user="Vue" data-slug-hash="NWqLjqy" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="v-for with Object">
9999
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/NWqLjqy">
@@ -102,7 +102,7 @@ Result:
102102
</p>
103103
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
104104

105-
You can also provide a second argument for the property's name (a.k.a. key):
105+
2 つ目の引数としてプロパティ名(すなわちキー)も提供できます:
106106

107107
```html
108108
<li v-for="(value, name) in myObject">
@@ -117,7 +117,7 @@ You can also provide a second argument for the property's name (a.k.a. key):
117117
</p>
118118
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
119119

120-
And another for the index:
120+
index も提供できます:
121121

122122
```html
123123
<li v-for="(value, name, index) in myObject">
@@ -133,38 +133,38 @@ And another for the index:
133133
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
134134

135135
:::tip Note
136-
When iterating over an object, the order is based on the enumeration order of `Object.keys()`, which isn't guaranteed to be consistent across JavaScript engine implementations.
136+
オブジェクトを反復処理するとき、順序は `Object.keys()` の列挙順のキーに基づいており、全ての JavaScript エンジンの実装で一貫性が保証されて**いません**
137137
:::
138138

139-
## Maintaining State
139+
## 状態の維持
140140

141-
When Vue is updating a list of elements rendered with `v-for`, by default it uses an "in-place patch" strategy. If the order of the data items has changed, instead of moving the DOM elements to match the order of the items, Vue will patch each element in-place and make sure it reflects what should be rendered at that particular index.
141+
Vue `v-for` で描画された要素のリストを更新する際、デフォルトでは “その場でパッチを適用する” (in-place patch) 戦略が用いられます。データのアイテムの順序が変更された場合、アイテムの順序に合わせて DOM 要素を移動する代わりに、 Vue は各要素にその場でパッチを適用して、その特定のインデックスに何を描画するべきかを確実に反映します。
142142

143-
This default mode is efficient, but **only suitable when your list render output does not rely on child component state or temporary DOM state (e.g. form input values)**.
143+
このデフォルトのモードは効率がいいです。しかしこれは、**描画されたリストが子コンポーネントの状態や、一時的な DOM の状態に依存していないときにだけ適しています (例: フォームのインプットの値)**
144144

145-
To give Vue a hint so that it can track each node's identity, and thus reuse and reorder existing elements, you need to provide a unique `key` attribute for each item:
145+
Vue が各ノードの識別情報を追跡できるヒントを与えるために、また、先ほど説明したような既存の要素の再利用と並び替えができるように、一意な `key` 属性を全てのアイテムに与える必要があります:
146146

147147
```html
148148
<div v-for="item in items" :key="item.id">
149149
<!-- content -->
150150
</div>
151151
```
152152

153-
It is recommended to provide a `key` attribute with `v-for` whenever possible, unless the iterated DOM content is simple, or you are intentionally relying on the default behavior for performance gains.
153+
繰り返される DOM の内容が単純な場合や、性能向上のためにデフォルトの動作に意図的に頼る場合を除いて、可能なときはいつでも `v-for` `key` 属性を与えることが推奨されます。
154154

155-
Since it's a generic mechanism for Vue to identify nodes, the `key` also has other uses that are not specifically tied to `v-for`, as we will see later in the guide.
155+
これは Vue がノードを識別する汎用的な仕組みなので、`key` はガイドの後半でわかるように `v-for` に縛られない他の用途もあります。
156156

157157
:::tip Note
158-
Don't use non-primitive values like objects and arrays as `v-for` keys. Use string or numeric values instead.
158+
オブジェクトや配列のような非プリミティブ値を `v-for` のキーとして使わないでください。代わりに、文字列や数値を使ってください。
159159
:::
160160

161-
For detailed usage of the `key` attribute, please see the [`key` API documentation](../api/special-attributes.html#key).
161+
`key` 属性の詳細な使い方は、[`key` API ドキュメント](../api/special-attributes.html#key)を参照してください。
162162

163-
## Array Change Detection
163+
## 配列の変化を検出
164164

165-
### Mutation Methods
165+
### 変更メソッド
166166

167-
Vue wraps an observed array's mutation methods so they will also trigger view updates. The wrapped methods are:
167+
Vue は画面の更新もトリガするために、監視された配列の変更メソッドをラップします。ラップされたメソッドは次のとおりです:
168168

169169
- `push()`
170170
- `pop()`
@@ -174,23 +174,23 @@ Vue wraps an observed array's mutation methods so they will also trigger view up
174174
- `sort()`
175175
- `reverse()`
176176

177-
You can open the console and play with the previous examples' `items` array by calling their mutation methods. For example: `example1.items.push({ message: 'Baz' })`.
177+
コンソールを開いて前の `items` 配列の例で変更メソッドを呼び出して試してみてください。例えば `example1.items.push({ message: 'Baz' })` のようにしてみましょう。
178178

179-
### Replacing an Array
179+
### 配列の置き換え
180180

181-
Mutation methods, as the name suggests, mutate the original array they are called on. In comparison, there are also non-mutating methods, e.g. `filter()`, `concat()` and `slice()`, which do not mutate the original array but **always return a new array**. When working with non-mutating methods, you can replace the old array with the new one:
181+
変更メソッドは、名前が示唆するように、それらが呼ばれると元の配列を変更します。一方で、変更しないメソッドもあります。例えば、`filter()``concat()``slice()` は、元の配列を変更せず、**常に新しい配列**を返します。これらのメソッドを使用する場合は、新しいもので古い配列を置き換えることで変更できます:
182182

183183
```js
184184
example1.items = example1.items.filter(item => item.message.match(/Foo/))
185185
```
186186

187-
You might think this will cause Vue to throw away the existing DOM and re-render the entire list - luckily, that is not the case. Vue implements some smart heuristics to maximize DOM element reuse, so replacing an array with another array containing overlapping objects is a very efficient operation.
187+
これにより、Vue が既存の DOM を破棄し、リスト全体を再描画すると思われるかもしれませんが、幸いなことにそうではありません。Vue DOM 要素の再利用を最大化するためにいくつかのスマートなヒューリスティックを実装しているので、重複するオブジェクトを含んでいる別の配列で元の配列を置き換えることは、とても効率的な操作です。
188188

189-
## Displaying Filtered/Sorted Results
189+
## フィルタ/ソートされた結果の表示
190190

191-
Sometimes we want to display a filtered or sorted version of an array without actually mutating or resetting the original data. In this case, you can create a computed property that returns the filtered or sorted array.
191+
元のデータを実際に変更またはリセットせずに、フィルタリングやソートされたバージョンの配列を表示したいことがあります。このケースでは、フィルタリングやソートされた配列を返す算出プロパティを作ることができます。
192192

193-
For example:
193+
例えば:
194194

195195
```html
196196
<li v-for="n in evenNumbers">{{ n }}</li>
@@ -209,7 +209,7 @@ computed: {
209209
}
210210
```
211211

212-
In situations where computed properties are not feasible (e.g. inside nested `v-for` loops), you can use a method:
212+
算出プロパティが使えない状況ではメソッドを使うこともできます。(例: 入れ子になった v-for のループの中):
213213

214214
```html
215215
<ul v-for="numbers in sets">
@@ -230,17 +230,17 @@ methods: {
230230
}
231231
```
232232

233-
## `v-for` with a Range
233+
## 範囲付き `v-for`
234234

235-
`v-for` can also take an integer. In this case it will repeat the template that many times.
235+
`v-for` は整数値を取ることもできます。このケースでは、指定された数だけテンプレートが繰り返されます。
236236

237237
```html
238238
<div id="range" class="demo">
239239
<span v-for="n in 10">{{ n }} </span>
240240
</div>
241241
```
242242

243-
Result:
243+
結果:
244244

245245
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="NWqLjNY" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="v-for with a range">
246246
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/NWqLjNY">
@@ -249,9 +249,9 @@ Result:
249249
</p>
250250
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
251251

252-
## `v-for` on a `<template>`
252+
## `<template>` での `v-for`
253253

254-
Similar to template `v-if`, you can also use a `<template>` tag with `v-for` to render a block of multiple elements. For example:
254+
テンプレート `v-if` と同様に、複数の要素のブロックをレンダリングするために、 `v-for``<template>` タグを使うこともできます。例:
255255

256256
```html
257257
<ul>
@@ -262,23 +262,23 @@ Similar to template `v-if`, you can also use a `<template>` tag with `v-for` to
262262
</ul>
263263
```
264264

265-
## `v-for` with `v-if`
265+
## `v-for` `v-if`
266266

267267
:::tip
268-
Note that it's **not** recommended to use `v-if` and `v-for` together. Refer to [style guide](../style-guide/#avoid-v-if-with-v-for-essential) for details.
268+
`v-if` `v-for` を同時に利用することは**推奨されません**。 詳細については [スタイルガイド](../style-guide/#avoid-v-if-with-v-for-essential) を参照ください。
269269
:::
270270

271-
When they exist on the same node, `v-for` has a higher priority than `v-if`. That means the `v-if` will be run on each iteration of the loop separately. This can be useful when you want to render nodes for only _some_ items, like below:
271+
それらが同じノードに存在するとき、 `v-for` `v-if` よりも高い優先度を持ちます。これは `v-if` がループの各繰り返しで実行されることを意味します。以下のように、これはいくつかの項目のみのノードを描画する場合に便利です。
272272

273273
```html
274274
<li v-for="todo in todos" v-if="!todo.isComplete">
275275
{{ todo }}
276276
</li>
277277
```
278278

279-
The above only renders the todos that are not complete.
279+
上記は、完了していない項目だけを描画します。
280280

281-
If instead, your intent is to conditionally skip execution of the loop, you can place the `v-if` on a wrapper element (or [`<template>`](conditional#conditional-groups-with-v-if-on-lt-template-gt)). For example:
281+
代わりに、ループの実行を条件付きでスキップすることを目的にしている場合は、ラッパー要素 (または [`<template>`](conditional#conditional-groups-with-v-if-on-lt-template-gt))上に `v-if` を配置できます。例えば:
282282

283283
```html
284284
<ul v-if="todos.length">
@@ -289,17 +289,17 @@ If instead, your intent is to conditionally skip execution of the loop, you can
289289
<p v-else>No todos left!</p>
290290
```
291291

292-
## `v-for` with a Component
292+
## コンポーネントと `v-for`
293293

294-
> This section assumes knowledge of [Components](component-basics.md). Feel free to skip it and come back later.
294+
> このセクションでは、[コンポーネント](component-basics.md)についての知識を前提としています。もし分からなければ、このセクションを遠慮なく飛ばして、理解した後に戻ってきてください。
295295
296-
You can directly use `v-for` on a custom component, like any normal element:
296+
通常の要素のように、カスタムコンポーネントで直接 `v-for` を使うことができます:
297297

298298
```html
299299
<my-component v-for="item in items" :key="item.id"></my-component>
300300
```
301301

302-
However, this won't automatically pass any data to the component, because components have isolated scopes of their own. In order to pass the iterated data into the component, we should also use props:
302+
ただし、コンポーネントは自身の隔離されたスコープを持っているため、これによってコンポーネントにデータが自動的に渡されることはありません。繰り返されたデータをコンポーネントに渡すには、プロパティも使用する必要があります:
303303

304304
```html
305305
<my-component
@@ -310,9 +310,9 @@ However, this won't automatically pass any data to the component, because compon
310310
></my-component>
311311
```
312312

313-
The reason for not automatically injecting `item` into the component is because that makes the component tightly coupled to how `v-for` works. Being explicit about where its data comes from makes the component reusable in other situations.
313+
自動的に `item` をコンポーネントに渡さない理由は、それが `v-for` の動作と密結合になってしまうからです。どこからデータが来たのかを明確にすることで、他の場面でコンポーネントを再利用できるようになります。
314314

315-
Here's a complete example of a simple todo list:
315+
これは、単純な ToDo リストの完全な例です:
316316

317317
```html
318318
<div id="todo-list-example">

0 commit comments

Comments
 (0)