HomeBanner.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="banner">
  3. <swiper class="bg" circular :indicator-dots="false" :autoplay="true" :interval="5000" :duration="200" @change="_bindChange">
  4. <swiper-item v-for="(item, index) in banners" :key="index">
  5. <view class="swiper">
  6. <image :src="item.image" @click.stop="goUrl(item.url)"></image>
  7. </view>
  8. </swiper-item>
  9. </swiper>
  10. <!-- 指示点 -->
  11. <view class="indicator-dots round">
  12. <view class="dots-item" :class="{ active: current == index }" v-for="(dataItem, index) in banners" :key="index"></view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. banners: {
  20. type: Array,
  21. default: []
  22. }
  23. },
  24. data() {
  25. return {
  26. current: 1 // 轮播图指针
  27. }
  28. },
  29. methods: {
  30. goUrl(url) {
  31. this.$navTo(url);
  32. },
  33. /**
  34. * 记录当前指针
  35. */
  36. _bindChange(e) {
  37. this.current = e.detail.current;
  38. }
  39. },
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .banner {
  44. position: relative;
  45. width: 100%;
  46. height: 600rpx;
  47. .bg {
  48. width: 100%;
  49. height: 600rpx;
  50. }
  51. }
  52. .banner,
  53. .bg,
  54. .swiper {
  55. width: 100%;
  56. height: 600rpx;
  57. image {
  58. width: 100%;
  59. height: 100%;
  60. }
  61. }
  62. /* 指示点 */
  63. .indicator-dots {
  64. width: 100%;
  65. height: 28rpx;
  66. padding: 10rpx;
  67. position: absolute;
  68. left: 0;
  69. right: 0;
  70. bottom: 70rpx;
  71. opacity: 0.8;
  72. display: flex;
  73. justify-content: center;
  74. .dots-item {
  75. width: 16rpx;
  76. height: 16rpx;
  77. margin-right: 8rpx;
  78. background-color: #333;
  79. border: solid 5rpx #fff;
  80. &:last-child {
  81. margin-right: 0;
  82. }
  83. &.active {
  84. background-color: #fff !important;
  85. }
  86. }
  87. // 圆形
  88. &.round .dots-item {
  89. width: 18rpx;
  90. height: 18rpx;
  91. border-radius: 18rpx;
  92. }
  93. }
  94. </style>