Carousel.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="carousel" :class="{width_670: providerType === 'original'}">
  3. <div v-swiper:mySwiper="swiperOption">
  4. <div class="swiper-wrapper">
  5. <div class="swiper-slide" v-for="banner in banners">
  6. <a :href="banner.hrefUrl" target="_blank">
  7. <img :src="banner.pictureUrl">
  8. </a>
  9. </div>
  10. </div>
  11. <div class="swiper-pagination swiper-pagination-bullets"></div>
  12. <div class="swiper-button-prev"><i class="iconfont icon-arrow-left"></i></div>
  13. <div class="swiper-button-next"><i class="iconfont icon-arrow-right"></i></div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import { carousel } from '~utils/mixin'
  19. export default {
  20. name: 'carousel',
  21. data () {
  22. return {
  23. activeSlide: 0
  24. // banners: {}
  25. }
  26. },
  27. mixins: [carousel],
  28. // mounted () {
  29. // this.$http.get('/api/carousel/home%20page%20banner')
  30. // .then(response => {
  31. // this.banners = response.data
  32. // this.x++
  33. // })
  34. // }
  35. computed: {
  36. providerType () {
  37. return this.$route.path === '/provider/home' ? 'agency' : 'original'
  38. },
  39. banners () {
  40. if (this.$store.state.carousel.banners) {
  41. let banner = this.$store.state.carousel.banners.data.slice()
  42. banner.sort(function (a, b) {
  43. return a.orderNumber - b.orderNumber
  44. })
  45. return banner
  46. } else {
  47. return ''
  48. }
  49. },
  50. swiperOption () {
  51. return {
  52. autoplay: 5000,
  53. initialSlide: 0,
  54. loop: true,
  55. effect: this.effect,
  56. lazyLoading: true,
  57. // 解决点击分页器后图片就不能轮播的问题
  58. autoplayDisableOnInteraction: false,
  59. pagination: '.swiper-pagination',
  60. paginationClickable: true,
  61. paginationElement: 'li',
  62. prevButton: '.swiper-button-prev',
  63. nextButton: '.swiper-button-next'
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. @import '~assets/scss/variables';
  71. $carousel_width: 910px;
  72. $carousel_width_670: 670px;
  73. $carousel_height: 358px;
  74. .carousel {
  75. &.width_670{
  76. width: $carousel_width_670;
  77. }
  78. width: $carousel_width;
  79. height: $carousel_height;
  80. transition: background-color .3s;
  81. position: relative;
  82. overflow: hidden;
  83. .swiper-wrapper {
  84. .swiper-slide {
  85. img {
  86. display: block;
  87. width: 100%;
  88. height: $carousel_height;
  89. }
  90. }
  91. }
  92. }
  93. </style>