index.html 1.9 KB

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