ImageGrid.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div class="w-100 d-flex flex-row flex-wrap" :style="{ gap: gap }">
  3. <slot
  4. name="item"
  5. v-for="(v, k) in data"
  6. :key="k"
  7. :item="v"
  8. :index="k"
  9. :width="`calc(${100 / rowCount}% - ${gap})`"
  10. :height="imageHeight"
  11. :url="imagekey ? v[imagekey] : v"
  12. >
  13. <img
  14. :src="imagekey ? v[imagekey] : v"
  15. :style="{
  16. width: `calc(${100 / rowCount}% - ${gap})`,
  17. height: imageHeight,
  18. borderRadius: '5px',
  19. objectFit: 'cover',
  20. }"
  21. @click="()=>emit('itemClick', v)"
  22. />
  23. </slot>
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. import type { PropType } from 'vue';
  28. defineProps({
  29. rowCount : {
  30. type: Number,
  31. default: 3,
  32. },
  33. imagekey : {
  34. type: String,
  35. default: undefined,
  36. },
  37. imageHeight : {
  38. type: String,
  39. default: undefined,
  40. },
  41. gap: {
  42. type: String,
  43. default: '10px',
  44. },
  45. data: {
  46. type: Object as PropType<any[]>,
  47. default: null,
  48. },
  49. })
  50. const emit = defineEmits([
  51. "itemClick"
  52. ])
  53. </script>