【已解决】 vue报错template’ cannot be keyed. Place the key on real elements instead
七娃博客
2,313人阅读
最近在使用vue开发项目时,随手写了一个template闭合标签,然后在标签上加了v-for和动态key,然后就引发了这次小”事故“:
(Emitted value instead of an instance of Error)
Error compiling template:
<template v-for="(item,index) in buttonGroup" :key="index">
</template>
- <template> cannot be keyed. Place the key on real elements instead.
然后,又将template 改成了 div,bug不见了!撤销回去,依旧使用template 不过 删除了key,bug也不见了!
看来,vue不允许在template 使用key。分析愿因可能是 template 不被渲染出来,无法将属性值和事件绑定上!不过 v-if/show都可以使用在template 身上。
主题开源不易,支持一下作者吧!
使用支付宝打赏
使用微信打赏
评论 | 0 条评论
登录之后才可留言,前往登录