17.组件.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. <haha></haha>
  11. <aa></aa>
  12. </div>
  13. <script src="./vue.js"></script>
  14. <script>
  15. // html => template
  16. // css
  17. // js
  18. // components
  19. /**
  20. * Vue.component('组件名',{
  21. * template`
  22. * 组件内容
  23. * `
  24. * })
  25. */
  26. // 1.全局组件
  27. Vue.component('haha',{
  28. template:`
  29. <h1>哈哈哈哈</h1>
  30. `
  31. })
  32. // 2.局部组件
  33. const blue = Vue.extend({
  34. template:`
  35. <ul>
  36. <li>aaa</li>
  37. <li>bbb</li>
  38. <li>ccc</li>
  39. </ul>
  40. `
  41. })
  42. var vm = new Vue({
  43. el: "#app",
  44. data: {
  45. msg: "哈哈哈"
  46. },
  47. components:{
  48. aa:blue
  49. }
  50. })
  51. </script>
  52. </body>
  53. </html>