SlideImage.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. <image class="slide-image" mode="aspectFill" :src="item"></image>
  8. </swiper-item>
  9. </swiper>
  10. <view class="banner-num">
  11. <text>{{ currentIndex }}</text>
  12. <text>/</text>
  13. <text>{{ images.length }}</text>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. images: {
  21. type: Array,
  22. default: []
  23. }
  24. },
  25. data() {
  26. return {
  27. indicatorDots: true, // 是否显示面板指示点
  28. autoplay: true, // 是否自动切换
  29. interval: 3000, // 自动切换时间间隔
  30. duration: 800, // 滑动动画时长
  31. currentIndex: 1 // 轮播图指针
  32. }
  33. },
  34. methods: {
  35. // 设置轮播图当前指针 数字
  36. setCurrent(e) {
  37. const app = this
  38. app.currentIndex = e.detail.current + 1
  39. },
  40. // 浏览商品图片
  41. onPreviewImages(index) {
  42. const app = this
  43. const imageUrls = []
  44. app.images.forEach(item => {
  45. imageUrls.push(item);
  46. });
  47. uni.previewImage({
  48. current: imageUrls[index],
  49. urls: imageUrls
  50. })
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. // swiper组件
  57. .swiper-box {
  58. width: 100%;
  59. height: 100vw;
  60. .slide-image {
  61. width: 100%;
  62. height: 100%;
  63. margin: 0rpx;
  64. padding: 0rpx;
  65. display: block;
  66. border-radius: 1rpx;
  67. }
  68. }
  69. /* banner计数 */
  70. .banner-num {
  71. position: absolute;
  72. right: 30rpx;
  73. margin-top: -70rpx;
  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>