banner.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view>
  3. <swiper :current="current" autoplay @change="onChange" :style="{height}">
  4. <swiper-item v-for="(item, index) in imgList" :key="index" class="banner-swipe">
  5. <image :src="item.imgPath" @click="onTap(item)"/>
  6. </swiper-item>
  7. </swiper>
  8. <view class="indication">
  9. <view :class="index === current? 'active':'default'" v-for="(item, index) in imgList" :key="index"></view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "banner",
  16. props: {
  17. imgList: Array,
  18. imageClass: String,
  19. height: String,
  20. },
  21. data() {
  22. return {
  23. current: 0,
  24. };
  25. },
  26. methods: {
  27. onChange(e){
  28. this.current = e.detail.current;
  29. },
  30. onTap(item) {
  31. this.$emit('banner',item);
  32. },
  33. }
  34. }
  35. </script>
  36. <style scoped>
  37. .banner-swipe {
  38. display: flex;
  39. justify-content: center;
  40. align-items: center;
  41. }
  42. .indication {
  43. display: flex;
  44. flex-direction: row;
  45. align-items: center;
  46. justify-content: center;
  47. margin-bottom: 10rpx;
  48. }
  49. .default {
  50. margin-right: 9rpx;
  51. width: 15rpx;
  52. height: 15rpx;
  53. background: #B9BBCD;
  54. border-radius: 15rpx;
  55. }
  56. .active {
  57. margin-right: 9rpx;
  58. width: 26rpx;
  59. height: 15rpx;
  60. background: #FF4330;
  61. border-radius: 7.5rpx;
  62. }
  63. </style>