@@ -294,9 +294,17 @@ Now we can pass the todo into each repeated component using `v-bind`:
294
294
``` html
295
295
<div id =" app-7" >
296
296
<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 >
300
308
</ol >
301
309
</div >
302
310
```
@@ -310,17 +318,17 @@ var app7 = new Vue({
310
318
el: ' #app-7' ,
311
319
data: {
312
320
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' }
316
324
]
317
325
}
318
326
})
319
327
```
320
328
{% raw %}
321
329
<div id =" app-7 " class =" demo " >
322
330
<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>
324
332
</ol >
325
333
</div >
326
334
<script >
@@ -332,9 +340,9 @@ var app7 = new Vue({
332
340
el: ' #app-7' ,
333
341
data: {
334
342
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' }
338
346
]
339
347
}
340
348
})
0 commit comments