Example01Basic.vue 3.5 KB

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