You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
1.9 KiB

3 years ago
  1. <template>
  2. <view class="home-banner">
  3. <swiper
  4. class="swiper"
  5. circular
  6. autoplay
  7. interval="5000"
  8. previous-margin="50rpx"
  9. next-margin="50rpx"
  10. @change="onSwiperChange"
  11. >
  12. <swiper-item class="item" v-for="(item, index) in list" :key="index" >
  13. <image
  14. class="pic"
  15. :class="{current: current === index}"
  16. :src="item.image"
  17. mode="aspectFill"
  18. @click="navTo(item.link)"
  19. ></image>
  20. </swiper-item>
  21. </swiper>
  22. <view class="dots row center">
  23. <view class="dot" :class="{current: current === index}" v-for="(item, index) in list" :key="index"></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'HomeBanner',
  30. data() {
  31. return {
  32. current: 0,
  33. /* list: [
  34. {image: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2221182985,1875035766&fm=26&gp=0.jpg'},
  35. {image: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2544696267,4055569904&fm=26&gp=0.jpg'},
  36. {image: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2573133749,533767849&fm=26&gp=0.jpg'},
  37. ] */
  38. };
  39. },
  40. props: {
  41. list: {
  42. type: Array,
  43. default(){
  44. return []
  45. }
  46. }
  47. },
  48. methods: {
  49. onSwiperChange(e){
  50. this.current = e.detail.current;
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped lang="scss">
  56. .home-banner{
  57. position: relative;
  58. background-color: #fff;
  59. }
  60. .swiper{
  61. width: 750rpx;
  62. height: 310rpx;
  63. padding-top: 10rpx;
  64. }
  65. .pic{
  66. display: block;
  67. width: 100%;
  68. height: 100%;
  69. border-radius: 16rpx;
  70. transform: scale(0.94, 0.88);
  71. transition: transform .36s;
  72. &.current{
  73. transform: scale(1);
  74. }
  75. }
  76. .dots{
  77. position: absolute;
  78. left: 0;
  79. bottom: 12rpx;
  80. width: 100%;
  81. }
  82. .dot{
  83. width: 32rpx;
  84. height: 8rpx;
  85. margin: 0 6rpx;
  86. background-color: #fff;
  87. border-radius: 10px;
  88. &.current{
  89. background-color: $base-color;
  90. }
  91. }
  92. </style>