What is the difference between :key and v-bind:key when constructing a v-for loop?
Asked Answered
W

1

5

There are examples in the Vue docs using the key keyword use both :key= and v-bind:key= when defining the key in a v-for loop. Is one just syntactic sugar of the other, or do they do different things?

Examples from the docs using both types:

:key

<my-component v-for="item in items" :key="item.id"></my-component>

v-bind:key

<my-component
  v-for="(item, index) in items"
  v-bind:item="item"
  v-bind:index="index"
  v-bind:key="item.id"
></my-component>
Weary answered 11/3, 2019 at 15:22 Comment(0)
S
12

:key= and v-bind:key= are exactly the same.

Source: https://v2.vuejs.org/v2/api/#v-bind

v-bind

Shorthand: :

Sestertium answered 11/3, 2019 at 15:25 Comment(1)
same as @click and v-on:clickBenco

© 2022 - 2024 — McMap. All rights reserved.