dra*_*035 15 vue.js v-for nuxt.js
在我的 Nuxt 应用程序中,我有以下行触发此问题标题中提到的错误:
<template v-for="(project, index) in existingProjects">
<span :key="project.projectId"></span>
Run Code Online (Sandbox Code Playgroud)
我试图:key在template元素上拥有该属性,我也尝试将其index用作键,但无济于事。
任何的想法?
BTL*_*BTL 24
有多种方法可以解决您的问题:
template:您必须在模板中的所有元素上放置一个键,因为您不能在 akey上放置 a template:<template> cannot be keyed. Place the key on real elements instead.<template v-for="(project, index) in existingProjects">
<span :key="project.projectId">foo</span>
<div :key="project.projectId">bar</div>
</template>
Run Code Online (Sandbox Code Playgroud)
template:您只需将key放在父 html 标签上。<div v-for="(project, index) in existingProjects" :key="project.projectId">
<span>foo</span>
<div>bar</div>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18221 次 |
| 最近记录: |