index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="swiper-box" :style="{height: height}">
  3. <u-swiper
  4. :list="list"
  5. :height="height"
  6. :radius="radius"
  7. style="width: 100%"
  8. :indicator="true"
  9. :show-title="true"
  10. indicator-mode="dot"
  11. :indicator-style="{bottom: '24rpx'}"
  12. @click="handleClick"
  13. @change="handleChange"
  14. >
  15. <view
  16. slot="indicator"
  17. class="indicator"
  18. >
  19. <view
  20. v-for="(item, index) in list"
  21. :key="index"
  22. class="indicator__dot"
  23. :class="[index === currentNum && 'indicator__dot--active']"
  24. />
  25. </view>
  26. </u-swiper>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'SwiperBox',
  32. props: {
  33. height: {
  34. type: [Number, String],
  35. default: '330rpx'
  36. },
  37. radius: {
  38. type: [Number, String],
  39. default: '10rpx'
  40. }
  41. },
  42. data() {
  43. return {
  44. list: [
  45. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  46. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  47. 'https://cdn.uviewui.com/uview/swiper/swiper3.png'
  48. ],
  49. currentNum: 0
  50. }
  51. },
  52. computed: {
  53. },
  54. created() {
  55. this.getSwiper()
  56. },
  57. methods: {
  58. handleClick(index) {
  59. const item = this.list[index]
  60. console.log('-->data', item)
  61. },
  62. handleChange(e) {
  63. this.currentNum = e.current
  64. },
  65. getSwiper() {
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .swiper-box{
  72. margin: 20rpx 0;
  73. .indicator {
  74. display: flex;
  75. flex-direction: row;
  76. justify-content: center;
  77. &__dot {
  78. height: 20rpx;
  79. width: 20rpx;
  80. border-radius: 50%;
  81. background-color: rgba(255, 255, 255, 0.35);
  82. margin: 0 10px;
  83. transition: background-color 0.3s;
  84. &--active {
  85. background-color: #6EEBE8;
  86. }
  87. }
  88. }
  89. }
  90. </style>