16_component.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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-com name="zhangsan" age="18">
  12. <ul>
  13. <li>1</li>
  14. <li>2</li>
  15. <li>3</li>
  16. </ul>
  17. </my-com>
  18. <my-coms></my-coms>
  19. </div>
  20. <div id="app1">
  21. <my-com></my-com>
  22. </div>
  23. <template id="temp1">
  24. <div>
  25. <p>{{name}}</p>
  26. 1111
  27. <p>{{age}}</p>
  28. <slot></slot>
  29. <h2>我是temp1</h2>
  30. <h2>我是模板</h2>
  31. </div>
  32. </template>
  33. <script src="./vue.js"></script>
  34. <script>
  35. //template 模板里面 要有一个最底层的div去嵌套
  36. Vue.component('my-coms', {
  37. template: '<h2>hahahahhaha</h2>'
  38. })
  39. new Vue({
  40. el: "#app",
  41. data: {
  42. msg: 1
  43. },
  44. components: {
  45. 'my-com': {
  46. template: '#temp1',
  47. props: ['name', 'age']
  48. }
  49. }
  50. })
  51. new Vue({
  52. el: '#app1'
  53. })
  54. </script>
  55. </body>
  56. </html>