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


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>
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM