Example03MultipleGrids.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div>
  3. <div style="margin-top:10px;">
  4. <h4>Grid #1</h4>
  5. <grid-layout :layout.sync="layout"
  6. :col-num="12"
  7. :row-height="30"
  8. :is-draggable="true"
  9. :is-resizable="true"
  10. :vertical-compact="true"
  11. :use-css-transforms="true"
  12. >
  13. <grid-item v-for="item in layout"
  14. :x="item.x"
  15. :y="item.y"
  16. :w="item.w"
  17. :h="item.h"
  18. :i="item.i"
  19. >
  20. <span class="text">{{item.i}}</span>
  21. </grid-item>
  22. </grid-layout>
  23. </div>
  24. <div style="margin-top:10px;">
  25. <h4>Grid #2</h4>
  26. <grid-layout :layout="layout2"
  27. :col-num="12"
  28. :row-height="30"
  29. :is-draggable="true"
  30. :is-resizable="true"
  31. :vertical-compact="true"
  32. :use-css-transforms="true"
  33. >
  34. <grid-item v-for="item in layout2"
  35. :x="item.x"
  36. :y="item.y"
  37. :w="item.w"
  38. :h="item.h"
  39. :i="item.i"
  40. >
  41. <span class="text">{{item.i}}</span>
  42. </grid-item>
  43. </grid-layout>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { GridLayout, GridItem } from "vue-grid-layout"
  49. export default {
  50. components: {
  51. GridLayout,
  52. GridItem
  53. },
  54. data() {
  55. return {
  56. layout: [
  57. {"x":0,"y":0,"w":2,"h":2,"i":"0"},
  58. {"x":2,"y":0,"w":2,"h":4,"i":"1"},
  59. ],
  60. layout2: [
  61. {"x":0,"y":0,"w":2,"h":2,"i":"0"},
  62. {"x":2,"y":0,"w":2,"h":4,"i":"1"},
  63. {"x":4,"y":0,"w":2,"h":2,"i":"2"},
  64. ],
  65. draggable: true,
  66. resizable: true,
  67. index: 0,
  68. eventLog: []
  69. }
  70. },
  71. watch: {
  72. eventLog: function() {
  73. const eventsDiv = this.$refs.eventsDiv;
  74. eventsDiv.scrollTop = eventsDiv.scrollHeight;
  75. }
  76. },
  77. methods: {
  78. moveEvent: function(i, newX, newY){
  79. const msg = "MOVE i=" + i + ", X=" + newX + ", Y=" + newY;
  80. this.eventLog.push(msg);
  81. console.log(msg);
  82. },
  83. movedEvent: function(i, newX, newY){
  84. const msg = "MOVED i=" + i + ", X=" + newX + ", Y=" + newY;
  85. this.eventLog.push(msg);
  86. console.log(msg);
  87. },
  88. resizeEvent: function(i, newH, newW, newHPx, newWPx){
  89. const msg = "RESIZE i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  90. this.eventLog.push(msg);
  91. console.log(msg);
  92. },
  93. resizedEvent: function(i, newX, newY, newHPx, newWPx){
  94. const msg = "RESIZED i=" + i + ", X=" + newX + ", Y=" + newY + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  95. this.eventLog.push(msg);
  96. console.log(msg);
  97. },
  98. containerResizedEvent: function(i, newH, newW, newHPx, newWPx){
  99. const msg = "CONTAINER RESIZED i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  100. this.eventLog.push(msg);
  101. console.log(msg);
  102. },
  103. layoutCreatedEvent: function(newLayout){
  104. this.eventLog.push("Created layout");
  105. console.log("Created layout: ", newLayout)
  106. },
  107. layoutBeforeMountEvent: function(newLayout){
  108. this.eventLog.push("beforeMount layout");
  109. console.log("beforeMount layout: ", newLayout)
  110. },
  111. layoutMountedEvent: function(newLayout){
  112. this.eventLog.push("Mounted layout");
  113. console.log("Mounted layout: ", newLayout)
  114. },
  115. layoutReadyEvent: function(newLayout){
  116. this.eventLog.push("Ready layout");
  117. console.log("Ready layout: ", newLayout)
  118. },
  119. layoutUpdatedEvent: function(newLayout){
  120. this.eventLog.push("Updated layout");
  121. console.log("Updated layout: ", newLayout)
  122. },
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. .vue-grid-layout {
  128. background: #eee;
  129. }
  130. .vue-grid-item:not(.vue-grid-placeholder) {
  131. background: #ccc;
  132. border: 1px solid black;
  133. }
  134. .vue-grid-item .resizing {
  135. opacity: 0.9;
  136. }
  137. .vue-grid-item .static {
  138. background: #cce;
  139. }
  140. .vue-grid-item .text {
  141. font-size: 24px;
  142. text-align: center;
  143. position: absolute;
  144. top: 0;
  145. bottom: 0;
  146. left: 0;
  147. right: 0;
  148. margin: auto;
  149. height: 100%;
  150. width: 100%;
  151. }
  152. .vue-grid-item .no-drag {
  153. height: 100%;
  154. width: 100%;
  155. }
  156. .vue-grid-item .minMax {
  157. font-size: 12px;
  158. }
  159. .vue-grid-item .add {
  160. cursor: pointer;
  161. }
  162. .vue-draggable-handle {
  163. position: absolute;
  164. width: 20px;
  165. height: 20px;
  166. top: 0;
  167. left: 0;
  168. background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat;
  169. background-position: bottom right;
  170. padding: 0 8px 8px 0;
  171. background-repeat: no-repeat;
  172. background-origin: content-box;
  173. box-sizing: border-box;
  174. cursor: pointer;
  175. }
  176. .layoutJSON {
  177. background: #ddd;
  178. border: 1px solid black;
  179. margin-top: 10px;
  180. padding: 10px;
  181. }
  182. .eventsJSON {
  183. background: #ddd;
  184. border: 1px solid black;
  185. margin-top: 10px;
  186. padding: 10px;
  187. height: 100px;
  188. overflow-y: scroll;
  189. }
  190. </style>