cm-banner.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="banner" v-if="list.length > 0">
  3. <uni-swiper-dot :info="list" :current="current" mode="dot" :dotsStyles="dotsStyles">
  4. <swiper
  5. :indicator-dots="false"
  6. :autoplay="autoplay"
  7. :interval="interval"
  8. :duration="duration"
  9. :circular="true"
  10. :style="{ height: height }"
  11. :current="current"
  12. @change="onChange"
  13. >
  14. <swiper-item v-for="(item, index) in list" :key="index">
  15. <view class="swiper-item" :style="[{ margin: margin }]" @click.stop="$emit('click', index)">
  16. <image :src="item" :style="{ borderRadius: radius }"></image>
  17. </view>
  18. </swiper-item>
  19. </swiper>
  20. </uni-swiper-dot>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'cm-banner',
  26. props: {
  27. list: {
  28. type: Array,
  29. default: () => []
  30. },
  31. current: {
  32. type: Number,
  33. default: 0
  34. },
  35. autoplay: {
  36. type: Boolean,
  37. default: true
  38. },
  39. interval: {
  40. type: Number,
  41. default: 3000
  42. },
  43. duration: {
  44. type: Number,
  45. default: 200
  46. },
  47. margin: {
  48. type: String,
  49. default: '0 24rpx'
  50. },
  51. radius: {
  52. type: String,
  53. default: '16rpx'
  54. },
  55. height: {
  56. type: String,
  57. default: '340rpx'
  58. }
  59. },
  60. data() {
  61. return {
  62. dotsStyles: {
  63. width: 6,
  64. bottom: 8,
  65. color: 'background: rgba(255, 255, 255, 0.39)',
  66. backgroundColor: 'background: rgba(255, 255, 255, 0.39)',
  67. border: '0',
  68. selectedBackgroundColor: '#FF457B',
  69. selectedBorder: '#FF457B'
  70. }
  71. }
  72. },
  73. methods: {
  74. onChange(e) {
  75. this.$emit('change', e.detail.current)
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .swiper-item {
  82. overflow: hidden;
  83. height: 100%;
  84. image {
  85. display: block;
  86. width: 100%;
  87. height: 100%;
  88. }
  89. }
  90. </style>