Example06Responsive.vue 4.1 KB

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