javascript - 当我想写数组时 v-for 返回错误
问题描述
我希望我的数组数据显示在列表中,但我看到以下错误:
error: Elements in iteration expect to have 'v-bind:key' directives (vue/require-v-for-key) at src\components\Kubismyk.vue:5:9:
我的组件:
<template>
<div>
<h1>{{ title }}</h1>
<ul>
<li v-for="ninja in ninjas">{{ ninja }}</li>
</ul>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {
title:'hello world',
ninjas: ['yoshi','mario','ryu']
}
}
}
</script>
解决方案
使用 v-for 时需要绑定 v-key:
<ul v-for="ninja in ninjas" v-bind:key="ninja.id">
<li>{{ ninja.name }}
</ul>```
推荐阅读
- azure-functions - azure function 和 aks cluster 之间使用 GRPC 通信
- java - 将 probuf 转换为 POJO
- python - Flask 中的原子插入
- javascript - 从内存流创建新的 Image 对象在生产中不起作用,但在本地工作
- ipfs - 无法从 vuejs 中的 ipfs 获取图像
- reactjs - React Jest 快照等待重新渲染
- python - 二叉树遍历中的RecursionError
- javascript - 使用 Javascript 动态包含树枝
- javascript - 相同的键 WeakMaps 是否阻塞?
- javascript - 为什么浏览器(之前访问过的)会加载我网站的旧版本?