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

戏子无情 提交于 2020-07-21 04:25:04

问题


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>

回答1:


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

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

v-bind

Shorthand: :



来源:https://stackoverflow.com/questions/55105160/what-is-the-difference-between-key-and-v-bindkey-when-constructing-a-v-for-loo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!