解決方案
v-for應該寫在#app定義的內部,而不是平級
錯誤的代碼,v-for 寫在了#app平級
1 body> 2 3 <section id="app" v-for='item in monster'> 4 <table> 5 <tr> 6 <th>名稱</th> 7 </tr> 8 <tr> 9 <td>{{item}}</td> 10 <td>{{item.name}}</td> 11 </tr> 12 13 </table> 14 </section> 15 16 <script> 17 var app = new Vue({ 18 el: '#app', 19 data: { 20 monster: [ 21 { name: '獨眼蝙蝠', lv: 1, hp: 100 }, 22 { name: '彭哚菇', lv: 3, hp: 300 } 23 ] 24 }, 25 methods: {}, 26 }) 27 </script> 28 </body>
正確的代碼,寫在app定義的內部
1 <body> 2 3 <section id="app"> 4 <table v-for='item in monster'> 5 <tr> 6 <th>名稱</th> 7 </tr> 8 <tr> 9 <td>{{item}}</td> 10 <td>{{item.name}}</td> 11 </tr> 12 13 </table> 14 </section> 15 16 <script> 17 var app = new Vue({ 18 el: '#app', 19 data: { 20 monster: [ 21 { name: '獨眼蝙蝠', lv: 1, hp: 100 }, 22 { name: '彭哚菇', lv: 3, hp: 300 } 23 ] 24 }, 25 methods: {}, 26 }) 27 </script> 28 </body>