vue2和vue3 template v-for key的位置

报错‘<template v-for>‘ cannot be keyed. Place the key on real elements instead

vue2:<template> 标签不能拥有 key

<template v-for="i in list">
  <div :key="'index-' + i.id"></div>
</template>

vue3:key 则应该被设置在 <template> 标签上

 <template v-for="(i, index) in list" :key="index">
  <div>...</div>
  <span>...</span>
</template>

 

posted @ 2025-07-15 10:21  霓裳依旧  阅读(116)  评论(0)    收藏  举报