template cannot be keyed. Place the key on real elements instead.
一、總結
一句話總結:
原因:vue不支持在 template 元素上綁定屬性。比如這里想綁定 key 屬性就不行。
解決方法:可以改成div或者 不使用template元素做for循環
二、cannot be keyed. Place the key on real elements instead.
轉自或參考:cannot be keyed. Place the key on real elements instead.
https://blog.csdn.net/tangxinzhuan/article/details/89187057
<--! 以下代碼編譯的時候提示錯誤 -->
<template v-for="(m, key) in menus" :key="m.id">
{{m.menuName}}
</template>
原因:
不支持在 <template> 元素上綁定屬性。比如這里想綁定 key 屬性就不行。
解決辦法:
改用 <div> 元素。
<div v-for="(m, key) in menus" :key="m.id">
{{m.menuName}}
</div>