index.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vue.js Modal Example</title>
  6. <script src="../../dist/vue.js"></script>
  7. <link rel="stylesheet" href="style.css">
  8. </head>
  9. <body>
  10. <!-- template for the modal component -->
  11. <script type="text/x-template" id="modal-template">
  12. <div class="modal-mask" transition="modal">
  13. <div class="modal-wrapper">
  14. <div class="modal-container">
  15. <div class="modal-header">
  16. <slot name="header">
  17. default header
  18. </slot>
  19. </div>
  20. <div class="modal-body">
  21. <slot name="body">
  22. default body
  23. </slot>
  24. </div>
  25. <div class="modal-footer">
  26. <slot name="footer">
  27. default footer
  28. <button class="modal-default-button" @click="$emit('close')">
  29. OK
  30. </button>
  31. </slot>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </script>
  37. <!-- app -->
  38. <div id="app">
  39. <button id="show-modal" @click="showModal = true">Show Modal</button>
  40. <!-- use the modal component, pass in the prop -->
  41. <modal v-if="showModal" @close="showModal = false">
  42. <!--
  43. you can use custom content here to overwrite
  44. default content
  45. -->
  46. <h3 slot="header">custom header</h3>
  47. </modal>
  48. </div>
  49. <script>
  50. // register modal component
  51. Vue.component('modal', {
  52. template: '#modal-template'
  53. })
  54. // start app
  55. new Vue({
  56. el: '#app',
  57. data: {
  58. showModal: false
  59. }
  60. })
  61. </script>
  62. </body>
  63. </html>