banner.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="banner" :class="'terminal' + terminal">
  3. <swiper
  4. class="swiper" :circular="true" :indicator-dots="false" :autoplay="true"
  5. :style="{ 'height': bannerHeight + 'rpx' }" @change="swiperChange"
  6. >
  7. <swiper-item
  8. v-for="(item, index) in bannerList" :key="index" class="banner-item"
  9. :style="{ backgroundImage: 'url(' + item.bannerUrl + ')' }" @click="jumpLink(item.linkObj)"
  10. >
  11. <!-- <div class="a-link" @click="jumpLink(item.linkObj)"><img class="img" :src="item.bannerUrl" v-show="item.bannerUrl" mode="widthFix"></div> -->
  12. </swiper-item>
  13. </swiper>
  14. <view v-if="bannerList && bannerList.length > 1" class="swiper-dots">
  15. <text
  16. v-for="(dot, index) in bannerList.length" :key="index" class="dot"
  17. :class="index === swiperCurrent && 'dot-active'"
  18. ></text>
  19. </view>
  20. </div>
  21. </template>
  22. <script>
  23. import { funMixin } from '../config/mixin'
  24. export default {
  25. name: 'ShopBanner',
  26. mixins: [ funMixin ],
  27. props: {
  28. terminal: {
  29. type: Number,
  30. default: 4
  31. },
  32. componentContent: {
  33. type: Object
  34. }
  35. },
  36. data() {
  37. return {
  38. bannerHeight: 0,
  39. swiperCurrent: 0
  40. }
  41. },
  42. computed: {
  43. bannerList() {
  44. return this.componentContent.bannerData.filter(function (item) {
  45. return item.bannerUrl
  46. })
  47. }
  48. },
  49. mounted() {
  50. this.bannerHeight = this.componentContent.height
  51. this.$forceUpdate() // 刷新轮播图
  52. },
  53. methods: {
  54. swiperChange(e) {
  55. this.swiperCurrent = e.detail.current
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .banner {
  62. position: relative;
  63. .banner-item {
  64. width: 100%;
  65. background-repeat: no-repeat;
  66. background-position: center;
  67. background-size: auto 100%;
  68. img {
  69. display: none;
  70. }
  71. }
  72. &.terminal4 {
  73. ::v-deep .el-carousel {
  74. height: 100%;
  75. .el-carousel__container {
  76. height: 100%;
  77. }
  78. }
  79. .banner-item {
  80. background-repeat: no-repeat;
  81. background-position: center;
  82. background-size: auto 100%;
  83. img {
  84. display: none;
  85. }
  86. }
  87. }
  88. .swiper-dots {
  89. display: flex;
  90. position: absolute;
  91. left: 50%;
  92. transform: translateX(-50%);
  93. bottom: 20upx;
  94. z-index: 200;
  95. .dot {
  96. width: 12upx;
  97. height: 12upx;
  98. background: #FFFFFF;
  99. border-radius: 6upx;
  100. opacity: 0.2;
  101. margin: 0 10upx;
  102. }
  103. .dot-active {
  104. opacity: 1;
  105. width: 24upx;
  106. }
  107. }
  108. }
  109. </style>