index.vue 1.7 KB

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