【问题标题】:What is the difference between :key and v-bind:key when constructing a v-for loop?构造 v-for 循环时 :key 和 v-bind:key 有什么区别?
【发布时间】:2019-08-01 23:05:24
【问题描述】:

在 Vue 文档中有使用 key 关键字的示例,在 v-for 循环中定义键时同时使用 :key=v-bind:key=。一个只是另一个的语法糖,还是他们做不同的事情?

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>

【问题讨论】:

    标签: vue.js v-for


    【解决方案1】:

    :key=v-bind:key= 完全相同。

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

    v-bind

    简写::

    【讨论】:

    • 与@click 和 v-on:click 相同
    猜你喜欢
    • 2018-10-24
    • 2023-03-09
    • 2019-04-18
    • 2021-09-06
    • 1970-01-01
    • 2021-03-26
    • 2017-09-14
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多