我正在构建 HackerNews 的克隆并收到以下错误:
vue.esm.js?efeb:591 [Vue warn]: Avoid using non-primitive value as key, use string/number value instead.
found in
---> <Single> at src/components/Single.vue
<App> at src/App.vue
<Root>
错误似乎来自 Single.vue 但我无法工作它是什么?模板如下:
<template>
<div class="container">
<h2>{{ story.title }}</h2>
<p>Score: {{ story.score }}</p>
<p>{{ story.url }}</p>
<div v-for="comment in comments" :key="comment">
<div class="comment-wrap">
<div class="comment-block">
<p class="comment-text">{{ comment.text }}</p>
<div class="bottom-comment">
<div class="comment-author">{{ comment.by }}</div>
<div class="comment-date">{{ comment.time }}</div>
</div>
</div>
</div>
</div>
</div>
</template>
如果有人可以提供帮助,那就太好了!?
原文由 Drostan 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以简单地避免在
:key
中使用v-for
。正如 vuejs 文档 所说: