1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue局部组件的创建和使用</title> </head> <body> <div id="app"> <my-component :items="books"></my-component> <hr> <my-component :items="cars"></my-component> </div> <div id="app2"> </div> </body> <template id="my-component"> <ul> <li v-for="item in items"> {{ item.name }} - {{ item.price }}</li> </ul> </template> <script src="js/vue.js" type="text/javascript"></script> <script type="text/javascript"> var vm = new Vue({ el: '#app', components: { 'my-component': { props: ['items'], template: '#my-component' } }, data: { books: [{ name: '九阴真经', price: 2000 }, { name: '九阳真经', price: 3000 }, { name: '降龙十八掌', price: 500 }, ], cars: [{ name: '特斯拉', price: 300000 }, { name: '比亚迪', price: 200000 }] } }) new Vue({ el: '#app2' }) </script> </html>
|