17_vue组件is.html 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. <div>
  11. <!-- 组件is指令可以动态切换组件 -->
  12. <div is="box2"></div>
  13. <!-- <box1></box1>
  14. <box2></box2> -->
  15. </div>
  16. </div>
  17. <template id="temp1">
  18. <div>
  19. <h1>组件一</h1>
  20. </div>
  21. </template>
  22. <template id="temp2">
  23. <div>
  24. <h1>组件二</h1>
  25. </div>
  26. </template>
  27. <script src="./js/vue.js"></script>
  28. <script>
  29. new Vue({
  30. el: '#app',
  31. components:{
  32. "box1":{
  33. template:"#temp1"
  34. },
  35. "box2":{
  36. template:"#temp2"
  37. }
  38. }
  39. })
  40. </script>
  41. </body>
  42. </html>