Guest User

Untitled

a guest
Sep 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <body>
  2. <button>open popup #1</button>
  3.  
  4. <popup
  5. inline-template
  6. >
  7. <div class="popup popup_1">
  8. Content #1
  9. </div>
  10. </popup>
  11.  
  12. <popup
  13. inline-template
  14. >
  15. <div class="popup popup_2">
  16. Content #2
  17. </div>
  18. </popup>
  19. </body>
  20. ...
  21.  
  22. <script>
  23. Vue.component('popup', {
  24. methods: {
  25. open: function() {
  26. // ...
  27. },
  28. }
  29. });
  30.  
  31. var app = new Vue({
  32. el: 'body',
  33. });
  34. </script>
  35.  
  36. <template id="template-popup-component">
  37. <button v-on:click="togglePopup">Toggle this popup</button>
  38. <div v-if="isShow" class="popup-content">
  39. <slot></slot>
  40. </div>
  41. </template>
  42. <popup>
  43. Hello, World!
  44. </popup>
  45.  
  46. Vue.component('popup', {
  47. template: '#template-popup-component',
  48. data: function() {
  49. return {
  50. isShow: false
  51. }
  52. },
  53. methods: {
  54. togglePopup: function() {
  55. this.isShow = !this.isShow;
  56. },
  57. }
  58. });
  59.  
  60. var app = new Vue({
  61. el: 'body',
  62. });
  63.  
  64. <body>
  65. <button
  66. @click="$refs.popup1.open()"
  67. >
  68. open popup #1
  69. </button>
  70.  
  71. <popup
  72. v-ref:popup-1
  73. inline-template
  74. >
  75. <div
  76. v-if="data.open"
  77. class="popup popup_1"
  78. >
  79. Content #1
  80. </div>
  81. </popup>
  82.  
  83. <popup
  84. v-ref:popup-2
  85. inline-template
  86. >
  87. <div
  88. v-if="data.open"
  89. class="popup popup_2">
  90. Content #2
  91. </div>
  92. </popup>
  93. </body>
  94. ...
  95.  
  96. <script>
  97. Vue.component('popup', {
  98. data: function() {
  99. return {
  100. data: {
  101. open: false
  102. }
  103. }
  104. },
  105. methods: {
  106. open: function() {
  107. this.data.open = true;
  108. },
  109. }
  110. });
  111.  
  112. var app = new Vue({
  113. el: 'body',
  114. });
  115. </script>
Add Comment
Please, Sign In to add comment