全局组件2.html 740 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <link href="../css/style.css" rel="stylesheet"> </head>
  9. <body>
  10. <div id="myApp">
  11. <ol>
  12. <game-item v-for="item in games" v-bind:game="item"></game-item>
  13. </ol>
  14. </div>
  15. <script>
  16. /* 组件定义:game-item */
  17. Vue.component('game-item', {
  18. props: ['game'],
  19. template: '<li>{{ game.title }}</li>'
  20. });
  21. /* Vue对象实例化 */
  22. var myApp = new Vue({
  23. el: '#myApp',
  24. data: {
  25. games: [
  26. { title: '斗地主' },
  27. { title: '打麻雀' },
  28. { title: 'UNO' }
  29. ]
  30. }
  31. });
  32. </script>
  33. </body>
  34. </html>