banner.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <view class="swiper-banner-box">
  4. <swiper
  5. v-if="list.length > 0"
  6. class="tui-banner-swiper tui-banner tui-skeleton-fillet"
  7. :autoplay="true"
  8. :interval="5000"
  9. :duration="500"
  10. @change="swiperChange"
  11. :circular="true"
  12. >
  13. <swiper-item v-for="(item, index) in list" :key="index">
  14. <image :src="item.image" class="tui-slide-image" mode="scaleToFill" />
  15. </swiper-item>
  16. </swiper>
  17. <swiper
  18. v-else
  19. class="tui-banner-swiper tui-banner tui-skeleton-fillet"
  20. :autoplay="true"
  21. :interval="5000"
  22. :duration="500"
  23. @change="swiperChange"
  24. :circular="true"
  25. >
  26. <swiper-item> <image :src="defaultbanner" class="tui-slide-image" mode="scaleToFill" /> </swiper-item>
  27. </swiper>
  28. <view class="swiper__dots-box" v-if="list.length > 1">
  29. <view
  30. v-for="(item, idx) in list"
  31. :key="idx"
  32. :class="[idx === current ? 'swiper__dots-long' : 'none']"
  33. :data-index="current"
  34. class="swiper__dots-item"
  35. >
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name: 'address',
  44. props: {
  45. list: {
  46. type: Array
  47. }
  48. },
  49. data() {
  50. return {
  51. current: 0,
  52. defaultbanner: 'https://static.caimei365.com/app/img/bg/icon-defaultbanner.png'
  53. }
  54. },
  55. created() {
  56. console.log(this.list)
  57. },
  58. computed: {},
  59. methods: {
  60. swiperChange(e) {
  61. //轮播图切换
  62. const index = e.detail.current
  63. this.current = index
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss">
  69. .swiper-banner-box {
  70. width: 100%;
  71. height: 240rpx;
  72. background: #ffffff;
  73. position: relative;
  74. background-size: cover;
  75. }
  76. .tui-banner-swiper {
  77. width: 700rpx;
  78. margin: 0 auto;
  79. height: 240rpx;
  80. border-radius: 16rpx;
  81. overflow: hidden;
  82. transform: translateY(0);
  83. margin-top: 16rpx;
  84. .banner-item {
  85. border-radius: 16rpx;
  86. }
  87. .tui-slide-image {
  88. width: 100%;
  89. height: 240rpx;
  90. display: block;
  91. }
  92. }
  93. .swiper__dots-box {
  94. position: absolute;
  95. bottom: 30rpx;
  96. left: 0;
  97. right: 0;
  98. /* #ifndef APP-NVUE */
  99. display: flex;
  100. /* #endif */
  101. flex: 1;
  102. flex-direction: row;
  103. justify-content: center;
  104. align-items: center;
  105. .swiper__dots-item {
  106. width: 8rpx;
  107. height: 8rpx;
  108. border-radius: 100%;
  109. margin-left: 6px;
  110. background-color: rgba(255, 255, 255, 0.7);
  111. }
  112. .swiper__dots-long {
  113. width: 35rpx;
  114. height: 8rpx;
  115. border-radius: 4rpx;
  116. background-color: #ffff;
  117. transition: all 0.4s;
  118. }
  119. }
  120. </style>