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