10_component.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <my-component></my-component>
  12. <my-com name="zs" age="18">
  13. <ul>
  14. <li>111</li>
  15. <li>222</li>
  16. </ul>
  17. <h2>xixixixi</h2>
  18. </my-com>
  19. <my-com1></my-com1>
  20. </div>
  21. <div id="temp1">
  22. <my-component></my-component>
  23. </div>
  24. <template id="tem1">
  25. <div>
  26. <h2>{{name}}</h2>
  27. <h2>{{age}}</h2>
  28. <!-- 插槽 -->
  29. <slot></slot>
  30. </div>
  31. </template>
  32. <script src="vue.js"></script>
  33. <script>
  34. Vue.component('my-component',{
  35. template: '<h2>哈哈哈哈哈</h2>'
  36. })
  37. new Vue({
  38. el:"#app",
  39. data:{
  40. },
  41. components:{
  42. 'my-com':{
  43. template: '#tem1',
  44. props:['name','age'] //接收调用该组件 父组件传过来的参数
  45. },
  46. 'my-com1':{
  47. template:'<h2>呵呵呵呵呵呵</h2>'
  48. }
  49. }
  50. })
  51. new Vue({
  52. el:"#temp1",
  53. data:{
  54. }
  55. })
  56. </script>
  57. </body>
  58. </html>