ImageSwiper.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <swiper
  3. class="image-swiper"
  4. circular
  5. :indicator-dots="true"
  6. :autoplay="true"
  7. :interval="2000"
  8. :duration="1000"
  9. :style="{
  10. height: `${height}rpx`,
  11. }"
  12. >
  13. <swiper-item v-for="(item, key) in images" :key="key">
  14. <view
  15. class="item"
  16. :style="{
  17. height: `${height}rpx`,
  18. backgroundImage: `url(${item})`,
  19. backgroundSize: 'cover',
  20. }"
  21. >
  22. <image
  23. :src="item"
  24. :style="{
  25. width: '100%',
  26. height: `${height}rpx`,
  27. borderRadius: '20rpx'
  28. }"
  29. mode="aspectFit"
  30. @click="onPreviewImage(key)"
  31. />
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. </template>
  36. <script setup lang="ts">
  37. import { useSwiperImagePreview } from '@/common/composeabe/SwiperImagePreview';
  38. import type { PropType } from 'vue';
  39. const props = defineProps({
  40. images: {
  41. type: Array as PropType<string[]>,
  42. default: () => [],
  43. },
  44. height: {
  45. type: Number as PropType<number>,
  46. default: 400,
  47. },
  48. })
  49. const { onPreviewImage } = useSwiperImagePreview(() => props.images || [])
  50. </script>
  51. <style lang="scss">
  52. .image-swiper {
  53. .item {
  54. display: flex;
  55. justify-content: center;
  56. align-items: center;
  57. }
  58. image {
  59. border-radius: 20rpx;
  60. }
  61. }
  62. </style>