yd-banner.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <u-swiper :list="bannerList" :keyName="keyName" previousMargin="20" nextMargin="20" circular height="150" @change="e => (current = e.current)" :autoplay="true" @click="handleSwiperClick">
  3. <view slot="indicator" class="indicator">
  4. <view class="indicator__dot" v-for="(item, index) in bannerList" :key="index" :class="[index === current && 'indicator__dot--active']"></view>
  5. </view>
  6. </u-swiper>
  7. </template>
  8. <script>
  9. /**
  10. * 广告滚动图
  11. */
  12. export default {
  13. name: 'yd-banner',
  14. components: {},
  15. props: {
  16. keyName: {
  17. type: String,
  18. default: 'url'
  19. },
  20. bannerList: {
  21. type: Array,
  22. default: () => []
  23. }
  24. },
  25. data() {
  26. return {
  27. current: 0,
  28. currentNum: 0
  29. }
  30. },
  31. methods: {
  32. handleSwiperClick(index) {
  33. console.log('点击了图片索引值:', index)
  34. }
  35. }
  36. }
  37. </script>
  38. <style lang="scss" scoped>
  39. .indicator {
  40. @include flex(row);
  41. justify-content: center;
  42. &__dot {
  43. height: 15rpx;
  44. width: 15rpx;
  45. border-radius: 100rpx;
  46. background-color: rgba(255, 255, 255, 0.35);
  47. margin: 0 10rpx;
  48. transition: background-color 0.3s;
  49. &--active {
  50. background-color: $custom-bg-color;
  51. }
  52. }
  53. }
  54. </style>