10
0

18.组件.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <div id="app">
  10. <!-- <Hello/>
  11. <my-com/> -->
  12. <vase/>
  13. </div>
  14. <script src="./vue.js"></script>
  15. <!--
  16. 组件:
  17. 全局组件:Vue.component
  18. Vue.component('组件名字',{组件模板})
  19. 直接使用组件名字即可
  20. 局部组件:Vue.extend
  21. const xxx = Vue.extend({组件模板})
  22. 在components:{
  23. aaa:xxx
  24. xxx:xxx => xxx 同词省略 自然渲染的就是xxx
  25. }
  26. 页面渲染的是aaa
  27. 全局组件直接使用
  28. 局部组件需要在components里注册后使用
  29. -->
  30. <script>
  31. // Vue.component('组件名字',{组件模板})
  32. Vue.component("Hello",{
  33. template: `<h1>你好</h1>`
  34. })
  35. const blue = Vue.extend({
  36. template: `<div>这是Vase</div>`
  37. })
  38. // Vue.component("my-com",{
  39. // template: `
  40. // <ul>
  41. // <li>1</li>
  42. // <li>2</li>
  43. // <li>3</li>
  44. // <li>4</li>
  45. // </ul>
  46. // `
  47. // })
  48. var app = new Vue({
  49. data:{},
  50. methods:{},
  51. computed:{},
  52. watch:{},
  53. components:{
  54. // 注册名字:注册组件
  55. vase:blue
  56. }
  57. }).$mount("#app");
  58. </script>
  59. </body>
  60. </html>