SlideImage.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <!-- 商品图片 -->
  3. <view class="images-swiper">
  4. <swiper class="swiper-box" :autoplay="autoplay" :duration="duration" :indicator-dots="indicatorDots"
  5. :interval="interval" :circular="true" @change="setCurrent">
  6. <swiper-item v-for="(item, index) in images" :key="index" @click="onPreviewImages(index)">
  7. <view class="slide-image">
  8. <image class="image" :src="item.preview_url"></image>
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. <view class="swiper-count">
  13. <text>{{ currentIndex }}</text>
  14. <text>/</text>
  15. <text>{{ images.length }}</text>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. images: {
  23. type: Array,
  24. default: []
  25. }
  26. },
  27. data() {
  28. return {
  29. indicatorDots: true, // 是否显示面板指示点
  30. autoplay: true, // 是否自动切换
  31. interval: 3000, // 自动切换时间间隔
  32. duration: 800, // 滑动动画时长
  33. currentIndex: 1 // 轮播图指针
  34. }
  35. },
  36. methods: {
  37. // 设置轮播图当前指针 数字
  38. setCurrent(e) {
  39. const app = this
  40. app.currentIndex = e.detail.current + 1
  41. },
  42. // 浏览商品图片
  43. onPreviewImages(index) {
  44. const app = this
  45. const imageUrls = []
  46. app.images.forEach(item => {
  47. imageUrls.push(item.preview_url);
  48. });
  49. uni.previewImage({
  50. current: imageUrls[index],
  51. urls: imageUrls
  52. })
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. // swiper组件
  59. .images-swiper {
  60. position: relative;
  61. }
  62. .swiper-box {
  63. width: 100%;
  64. height: 100vw;
  65. /* #ifdef H5 */
  66. max-width: 480px;
  67. max-height: 480px;
  68. margin: 0 auto;
  69. /* #endif */
  70. .slide-image {
  71. position: relative;
  72. width: 100%;
  73. height: 100%;
  74. .image {
  75. display: block;
  76. width: 100%;
  77. height: 100%;
  78. }
  79. }
  80. }
  81. // swiper计数
  82. .swiper-count {
  83. position: absolute;
  84. right: 30rpx;
  85. bottom: 36rpx;
  86. padding: 2rpx 18rpx;
  87. background: rgba(0, 0, 0, 0.363);
  88. border-radius: 50rpx;
  89. color: #fff;
  90. font-size: 26rpx;
  91. }
  92. </style>