18.组件.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. <my-com></my-com>
  11. <happy></happy>
  12. </div>
  13. <script src="./vue.js"></script>
  14. <script>
  15. // 全局组件:注册
  16. /**
  17. * Vue.component('组件名字',{
  18. * 组件模板
  19. * })
  20. */
  21. Vue.component("my-com", {
  22. template: `
  23. <div>111</div>
  24. `,
  25. });
  26. //局部注册 Vue.extend
  27. const blueMain = Vue.extend({
  28. template:`
  29. <ul>
  30. <li>今天1</li>
  31. <li>今天2</li>
  32. <li>今天3</li>
  33. <li>今天4</li>
  34. </ul>
  35. `
  36. })
  37. var app = new Vue({
  38. data:{
  39. },
  40. methods: {
  41. },
  42. created() {
  43. },
  44. computed: {
  45. },
  46. watch: {
  47. },
  48. components: {
  49. happy: blueMain
  50. }
  51. }).$mount("#app");
  52. </script>
  53. </body>
  54. </html>