Vue v-for "TypeError: Cannot read property 'XX' of undefined"


解決方案一

v-for(v,k)括號后面這里要加空格,不能貼着in,否則會報錯

 1 <body>
 2 
 3     <section id="app">
 4         <table v-for='(item,index ) in monster'>
 5             <tr>
 6                 <th>名稱</th>
 7             </tr>
 8             <tr>
 9                 <td>{{item}}</td>
10                 <td>{{item.name}}</td>
11                 <td>{{index}}</td>
12             </tr>
13            
14         </table>
15     </section>
16 
17     <script>
18         var app = new Vue({
19             el: '#app',
20             data: {
21                 monster: [
22                     { name: '獨眼蝙蝠', lv: 1, hp: 100 },
23                     { name: '彭哚菇', lv: 3, hp: 300 }
24                 ]
25             },
26             methods: {},
27         })
28     </script>
29 </body>

 

 

解決方案二

v-for寫的位置,出現了層級關系問題,修改v-for的位置可以解決


免責聲明!

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



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