Skip to content

Commit 3b47e3c

Browse files
committed
update guide v-for component usage
1 parent f882f02 commit 3b47e3c

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/v2/guide/index.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,17 @@ Now we can pass the todo into each repeated component using `v-bind`:
294294
``` html
295295
<div id="app-7">
296296
<ol>
297-
<!-- Now we provide each todo-item with the todo object -->
298-
<!-- it's representing, so that its content can be dynamic -->
299-
<todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
297+
<!--
298+
Now we provide each todo-item with the todo object
299+
it's representing, so that its content can be dynamic.
300+
We also need to provide each component with a "key",
301+
which will be explained later.
302+
-->
303+
<todo-item
304+
v-for="item in groceryList"
305+
v-bind:todo="item"
306+
v-bind:key="item.id">
307+
</todo-item>
300308
</ol>
301309
</div>
302310
```
@@ -310,17 +318,17 @@ var app7 = new Vue({
310318
el: '#app-7',
311319
data: {
312320
groceryList: [
313-
{ text: 'Vegetables' },
314-
{ text: 'Cheese' },
315-
{ text: 'Whatever else humans are supposed to eat' }
321+
{ id: 0, text: 'Vegetables' },
322+
{ id: 1, text: 'Cheese' },
323+
{ id: 2, text: 'Whatever else humans are supposed to eat' }
316324
]
317325
}
318326
})
319327
```
320328
{% raw %}
321329
<div id="app-7" class="demo">
322330
<ol>
323-
<todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
331+
<todo-item v-for="item in groceryList" v-bind:todo="item" :key="item.id"></todo-item>
324332
</ol>
325333
</div>
326334
<script>
@@ -332,9 +340,9 @@ var app7 = new Vue({
332340
el: '#app-7',
333341
data: {
334342
groceryList: [
335-
{ text: 'Vegetables' },
336-
{ text: 'Cheese' },
337-
{ text: 'Whatever else humans are supposed to eat' }
343+
{ id: 0, text: 'Vegetables' },
344+
{ id: 1, text: 'Cheese' },
345+
{ id: 2, text: 'Whatever else humans are supposed to eat' }
338346
]
339347
}
340348
})

0 commit comments

Comments
 (0)