GridPattern.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <svg aria-hidden="true">
  3. <defs>
  4. <pattern
  5. :id="patternId"
  6. :width="width"
  7. :height="height"
  8. patternUnits="userSpaceOnUse"
  9. :x="x"
  10. :y="y">
  11. <path :d="`M.5 ${height}V.5H${width}`" fill="none" />
  12. </pattern>
  13. <rect
  14. width="100%"
  15. height="100%"
  16. stroke-width="0"
  17. :fill="`url(#${patternId})`"/>
  18. <svg v-for="square in squares"
  19. :key="patternId+'-square-'+square"
  20. :x="x"
  21. :y="y"
  22. class="overflow-visible">
  23. <rect
  24. stroke-width="0"
  25. :key="`${square[0]}-${square[1]}`"
  26. :width="width + 1"
  27. :height="height + 1"
  28. :x="square[0] * width"
  29. :y="square[1] * height"/>
  30. </svg>
  31. </defs>
  32. </svg>
  33. </template>
  34. <script setup>
  35. const props = defineProps(['width', 'height', 'x', 'y', 'squares']);
  36. const patternId = ref(Math.floor(Math.random() * 100));
  37. </script>