GridLines.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div
  3. class="grid-lines"
  4. :style="style"
  5. ></div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, computed } from 'vue'
  9. export default defineComponent({
  10. name: 'grid-lines',
  11. props: {
  12. gridSize: {
  13. type: Number,
  14. default: 20,
  15. },
  16. gridColor: {
  17. type: String,
  18. default: 'rgba(100, 100, 100, 0.1)',
  19. },
  20. },
  21. setup(props) {
  22. const style = computed(() => {
  23. const gridSize = props.gridSize + 'px'
  24. const gridSpacing = props.gridSize - 1 + 'px'
  25. const gridColor = props.gridColor
  26. return {
  27. backgroundImage: `linear-gradient(transparent ${gridSpacing}, ${gridColor} ${gridSpacing}, ${gridColor} ${gridSize}), linear-gradient(90deg, transparent ${gridSpacing}, ${gridColor} ${gridSpacing}, ${gridColor} ${gridSize})`,
  28. backgroundSize: `${gridSize} ${gridSize}`,
  29. }
  30. })
  31. return {
  32. style,
  33. }
  34. },
  35. })
  36. </script>
  37. <style lang="scss" scoped>
  38. .grid-lines {
  39. position: absolute;
  40. top: 0;
  41. bottom: 0;
  42. left: 0;
  43. right: 0;
  44. background-position: 0 0;
  45. }
  46. </style>