topSwiper.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="carousel">
  3. <swiper :circular="true" duration="400" @change="swiperChange">
  4. <swiper-item class="swiper-item" v-for="(item, index) in imgList" :key="index">
  5. <view class="image-wrapper"><image :src="item" class="loaded" mode="scaleToFill"></image></view>
  6. </swiper-item>
  7. </swiper>
  8. <view class="swiper-dots">
  9. <text class="num">{{ swiperCurrent + 1 }}</text>
  10. <text class="sign">/</text>
  11. <text class="num">{{ imgList | num }}</text>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. imgList: {
  19. type: Array,
  20. default: function () {
  21. return []
  22. }
  23. },
  24. },
  25. data() {
  26. return {
  27. swiperCurrent: 0,
  28. swiperLength: 0
  29. };
  30. },
  31. filters: {
  32. num(val) {
  33. if(val){
  34. return val.length
  35. }
  36. return 0
  37. }
  38. },
  39. methods: {
  40. swiperChange(e) {
  41. let index = e.detail.current;
  42. this.swiperCurrent = index;
  43. }
  44. }
  45. };
  46. </script>
  47. <style lang="scss">
  48. .carousel {
  49. /* #ifdef APP-PLUS */
  50. padding-top: var(--status-bar-height);
  51. /* #endif */
  52. height: 520rpx;
  53. position: relative;
  54. swiper {
  55. height: 100%;
  56. }
  57. .image-wrapper {
  58. width: 100%;
  59. height: 100%;
  60. }
  61. .swiper-item {
  62. display: flex;
  63. justify-content: center;
  64. align-content: center;
  65. height: 700rpx;
  66. overflow: hidden;
  67. image {
  68. width: 100%;
  69. height: 100%;
  70. }
  71. }
  72. }
  73. .swiper-dots {
  74. position: absolute;
  75. bottom: 30rpx;
  76. right: 26rpx;
  77. color: red;
  78. background-color: red;
  79. z-index: 99;
  80. width: 88rpx;
  81. height: 42rpx;
  82. background: #000000;
  83. opacity: 0.5;
  84. border-radius: 21rpx;
  85. font-size: 28rpx;
  86. font-family: PingFang SC;
  87. font-weight: 500;
  88. color: #FFFFFF;
  89. line-height: 42rpx;
  90. text-align: center;
  91. }
  92. </style>