最近在使用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.

vue报错template’ cannot be keyed. Place the key on real elements instead-QUI-Notes

然后,又将template  改成了 div,bug不见了!撤销回去,依旧使用template  不过 删除了key,bug也不见了!

总结

看来,vue不允许在template 使用key。分析愿因可能是 template 不被渲染出来,无法将属性值和事件绑定上!不过 v-if/show都可以使用在template 身上。