<template> cannot be keyed. Place the key on real elements instead.

问题遇到的现象和发生背景

uniapp中 推荐用 template 标签 于是无论是循环还是判断 我都用它 后来循环就报错

<template> cannot be keyed. Place the key on real elements instead

下面是uniapp官网的两个截图 例子中:
template v-for 没有指定 :key 但是block指定了 以前咱也没注意过

img

img

问题相关代码,请勿粘贴截图
<block v-for="(item,index) in list" :key="item.id"> view </block>

<!-- 下面这种就报错 -->
<template v-for="(item,index) in list" :key="item.id"> view </template>

我想要达到的结果

有没有da lao看看是什么原理 这两个元素的性质应该是差不多的

错误说得很明白了,template不支持key,要将key放到实际的element对象上

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632