SlideImage.vue 2.0 KB

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