index.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. <transition name="modal">
  13. <div class="modal-mask">
  14. <div class="modal-wrapper">
  15. <div class="modal-container">
  16. <div class="modal-header">
  17. <slot name="header">
  18. default header
  19. </slot>
  20. </div>
  21. <div class="modal-body">
  22. <slot name="body">
  23. default body
  24. </slot>
  25. </div>
  26. <div class="modal-footer">
  27. <slot name="footer">
  28. default footer
  29. <button class="modal-default-button" @click="$emit('close')">
  30. OK
  31. </button>
  32. </slot>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </transition>
  38. </script>
  39. <!-- app -->
  40. <div id="app">
  41. <button id="show-modal" @click="showModal = true">Show Modal</button>
  42. <!-- use the modal component, pass in the prop -->
  43. <modal v-if="showModal" @close="showModal = false">
  44. <!--
  45. you can use custom content here to overwrite
  46. default content
  47. -->
  48. <h3 slot="header">custom header</h3>
  49. </modal>
  50. </div>
  51. <script>
  52. // register modal component
  53. Vue.component('modal', {
  54. template: '#modal-template'
  55. })
  56. // start app
  57. new Vue({
  58. el: '#app',
  59. data: {
  60. showModal: false
  61. }
  62. })
  63. </script>
  64. </body>
  65. </html>