index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <view v-if="!props.hide" :style="`width: ${props.width}; height: ${props.height};`">
  3. <view v-if="props.list?.length">
  4. <swiper
  5. class="swiper"
  6. circular
  7. :indicator-dots="props.indicatorDots"
  8. :autoplay="props.autoplay"
  9. :interval="props.interval"
  10. :duration="props.duration"
  11. >
  12. <swiper-item v-for="(item, index) in list" :key="'swiperItem'+index">
  13. <view>
  14. <image
  15. :mode="strType ? props.mode : item.mode"
  16. :src="strType ? item : item[props.imgUrlKey]"
  17. :style="`width: ${props.width}; height: ${props.height};`"
  18. @error="imageError"
  19. ></image>
  20. </view>
  21. </swiper-item>
  22. </swiper>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. const props = defineProps({
  28. list: { type: Array, default: () => [] },
  29. indicatorDots: { type: Boolean, default: true }, // 是否显示面板指示点
  30. autoplay: { type: Boolean, default: true }, // 是否自动切换
  31. interval: { type: Number, default: 3000 }, // 自动切换时间间隔
  32. duration: { type: Number, default: 500 }, // 滑动动画时长
  33. strType: { type: Boolean, default: true }, // 数组类型或者对象类型
  34. imgUrlKey: { type: String, default: 'src' },
  35. mode: { type: String, default: 'aspectFill' }, // 图片裁剪、缩放的模式。aspectFill保持纵横比缩放图片,只保证图片的短边能完全显示出来
  36. hide: { type: Boolean, default: false }, // 隐藏
  37. width: { type: String, default: '100%' },
  38. height: { type: String, default: '150px' },
  39. })
  40. const imageError = (e) => {
  41. console.error('image发生error事件,携带值为' + e?.detail?.errMsg)
  42. }
  43. </script>
  44. <style scoped lang="scss">
  45. </style>