index.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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="x/template" id="modal-template">
  12. <div class="modal-mask" v-show="show" 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"
  29. @click="show = false">
  30. OK
  31. </button>
  32. </slot>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </script>
  38. <script>
  39. // register modal component
  40. Vue.component('modal', {
  41. template: '#modal-template',
  42. props: {
  43. show: {
  44. type: Boolean,
  45. required: true,
  46. twoWay: true
  47. }
  48. }
  49. })
  50. </script>
  51. <!-- app -->
  52. <div id="app">
  53. <button id="show-modal" @click="showModal = true">Show Modal</button>
  54. <!-- use the modal component, pass in the prop -->
  55. <modal :show.sync="showModal">
  56. <!--
  57. you can use custom content here to overwrite
  58. default content
  59. -->
  60. <h3 slot="header">custom header</h3>
  61. </modal>
  62. </div>
  63. <script>
  64. // start app
  65. new Vue({
  66. el: '#app',
  67. data: {
  68. showModal: false
  69. }
  70. })
  71. </script>
  72. </body>
  73. </html>