index.html 1.7 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="modal.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. <script>
  38. // register modal component
  39. Vue.component('modal', {
  40. template: '#modal-template'
  41. })
  42. </script>
  43. <!-- app -->
  44. <div id="app">
  45. <button id="show-modal" @click="showModal = true">Show Modal</button>
  46. <!-- use the modal component, pass in the prop -->
  47. <modal v-if="showModal" @close="showModal = false">
  48. <!--
  49. you can use custom content here to overwrite
  50. default content
  51. -->
  52. <h3 slot="header">custom header</h3>
  53. </modal>
  54. </div>
  55. <script>
  56. // start app
  57. new Vue({
  58. el: '#app',
  59. data: {
  60. showModal: false
  61. }
  62. })
  63. </script>
  64. </body>
  65. </html>