23_components_slot.html 1.2 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. <script src="./js/vue.js"></script>
  8. <style>
  9. .box {
  10. width: 100px;
  11. height: 100px;
  12. background-color: red;
  13. margin: 10px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="app">
  19. <box>
  20. <template v-slot:tem1>
  21. <h1>hello</h1>
  22. <h2>world</h2>
  23. </template>
  24. <template v-slot:tem2>
  25. <ul>
  26. <li>1</li>
  27. <li>2</li>
  28. <li>3</li>
  29. </ul>
  30. </template>
  31. </box>
  32. </div>
  33. <template id="box-temp">
  34. <div class="container">
  35. <slot name="tem1"></slot>
  36. <div class="box">
  37. <slot name="tem2"></slot>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. let app = new Vue({
  43. el: '#app',
  44. components: {
  45. box: {
  46. template: "#box-temp",
  47. }
  48. }
  49. })
  50. </script>
  51. </body>
  52. </html>