A
A
Anton Seredny2018-03-10 11:14:41
Vue.js
Anton Seredny, 2018-03-10 11:14:41

Why (with examples) use :key when rendering lists?

The documentation says the following:

When Vue updates a list of elements controlled by the v-for directive, it defaults to an "update in place" strategy. If the order of the elements of an array or object has changed, Vue will not move the DOM elements, but will simply update each element in place to display the new data at the appropriate index.

You can explain with a real-life example why this is:
<div v-for="item in items" :key="item.id">
  <!— содержимое —>
</div>

Better than just looping without :key="item.id" ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-10
@0xD34F Vue.js

Not more than a month and a half ago, I answered a similar question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question