ExampleStylingPlaceholder.vue 3.7 KB

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