Example08ResponsivePredefinedLayouts.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div>
  3. <grid-layout :layout.sync="layout"
  4. :responsive-layouts="layouts"
  5. :col-num="12"
  6. :row-height="30"
  7. :is-draggable="draggable"
  8. :is-resizable="resizable"
  9. :vertical-compact="true"
  10. :use-css-transforms="true"
  11. :responsive="responsive"
  12. @breakpoint-changed="breakpointChangedEvent"
  13. >
  14. <grid-item v-for="item in layout"
  15. :x="item.x"
  16. :y="item.y"
  17. :w="item.w"
  18. :h="item.h"
  19. :i="item.i"
  20. >
  21. <span class="text">{{item.i}}</span>
  22. </grid-item>
  23. </grid-layout>
  24. </div>
  25. </template>
  26. <script>
  27. import { GridLayout, GridItem } from "vue-grid-layout"
  28. let testLayouts = {
  29. md: [
  30. {"x":0, "y":0, "w":2, "h":2, "i":"0"},
  31. {"x":2, "y":0, "w":2, "h":4, "i":"1"},
  32. {"x":4, "y":0, "w":2, "h":5, "i":"2"},
  33. {"x":6, "y":0, "w":2, "h":3, "i":"3"},
  34. {"x":2, "y":4, "w":2, "h":3, "i":"4"},
  35. {"x":4, "y":5, "w":2, "h":3, "i":"5"},
  36. {"x":0, "y":2, "w":2, "h":5, "i":"6"},
  37. {"x":2, "y":7, "w":2, "h":5, "i":"7"},
  38. {"x":4, "y":8, "w":2, "h":5, "i":"8"},
  39. {"x":6, "y":3, "w":2, "h":4, "i":"9"},
  40. {"x":0, "y":7, "w":2, "h":4, "i":"10"},
  41. {"x":2, "y":19, "w":2, "h":4, "i":"11"},
  42. {"x":0, "y":14, "w":2, "h":5, "i":"12"},
  43. {"x":2, "y":14, "w":2, "h":5, "i":"13"},
  44. {"x":4, "y":13, "w":2, "h":4, "i":"14"},
  45. {"x":6, "y":7, "w":2, "h":4, "i":"15"},
  46. {"x":0, "y":19, "w":2, "h":5, "i":"16"},
  47. {"x":8, "y":0, "w":2, "h":2, "i":"17"},
  48. {"x":0, "y":11, "w":2, "h":3, "i":"18"},
  49. {"x":2, "y":12, "w":2, "h":2, "i":"19"}
  50. ],
  51. lg: [
  52. {"x":0,"y":0,"w":2,"h":2,"i":"0"},
  53. {"x":2,"y":0,"w":2,"h":4,"i":"1"},
  54. {"x":4,"y":0,"w":2,"h":5,"i":"2"},
  55. {"x":6,"y":0,"w":2,"h":3,"i":"3"},
  56. {"x":8,"y":0,"w":2,"h":3,"i":"4"},
  57. {"x":10,"y":0,"w":2,"h":3,"i":"5"},
  58. {"x":0,"y":5,"w":2,"h":5,"i":"6"},
  59. {"x":2,"y":5,"w":2,"h":5,"i":"7"},
  60. {"x":4,"y":5,"w":2,"h":5,"i":"8"},
  61. {"x":6,"y":4,"w":2,"h":4,"i":"9"},
  62. {"x":8,"y":4,"w":2,"h":4,"i":"10"},
  63. {"x":10,"y":4,"w":2,"h":4,"i":"11"},
  64. {"x":0,"y":10,"w":2,"h":5,"i":"12"},
  65. {"x":2,"y":10,"w":2,"h":5,"i":"13"},
  66. {"x":4,"y":8,"w":2,"h":4,"i":"14"},
  67. {"x":6,"y":8,"w":2,"h":4,"i":"15"},
  68. {"x":8,"y":10,"w":2,"h":5,"i":"16"},
  69. {"x":10,"y":4,"w":2,"h":2,"i":"17"},
  70. {"x":0,"y":9,"w":2,"h":3,"i":"18"},
  71. {"x":2,"y":6,"w":2,"h":2,"i":"19"}
  72. ],
  73. };
  74. export default {
  75. components: {
  76. GridLayout,
  77. GridItem
  78. },
  79. data() {
  80. return {
  81. layouts: testLayouts,
  82. layout: testLayouts["lg"],
  83. draggable: true,
  84. resizable: true,
  85. responsive: true,
  86. }
  87. },
  88. methods: {
  89. breakpointChangedEvent: function(newBreakpoint, newLayout){
  90. console.log("BREAKPOINT CHANGED breakpoint=", newBreakpoint, ", layout: ", newLayout );
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .vue-grid-layout {
  97. background: #eee;
  98. }
  99. .vue-grid-item:not(.vue-grid-placeholder) {
  100. background: #ccc;
  101. border: 1px solid black;
  102. }
  103. .vue-grid-item .resizing {
  104. opacity: 0.9;
  105. }
  106. .vue-grid-item .static {
  107. background: #cce;
  108. }
  109. .vue-grid-item .text {
  110. font-size: 24px;
  111. text-align: center;
  112. position: absolute;
  113. top: 0;
  114. bottom: 0;
  115. left: 0;
  116. right: 0;
  117. margin: auto;
  118. height: 100%;
  119. width: 100%;
  120. }
  121. .vue-grid-item .no-drag {
  122. height: 100%;
  123. width: 100%;
  124. }
  125. .vue-grid-item .minMax {
  126. font-size: 12px;
  127. }
  128. .vue-grid-item .add {
  129. cursor: pointer;
  130. }
  131. .vue-draggable-handle {
  132. position: absolute;
  133. width: 20px;
  134. height: 20px;
  135. top: 0;
  136. left: 0;
  137. 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;
  138. background-position: bottom right;
  139. padding: 0 8px 8px 0;
  140. background-repeat: no-repeat;
  141. background-origin: content-box;
  142. box-sizing: border-box;
  143. cursor: pointer;
  144. }
  145. </style>