Carousel.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. export default {
  19. name: 'carousel',
  20. data () {
  21. return {
  22. activeSlide: 0,
  23. swiperOption: {
  24. autoplay: 5000,
  25. initialSlide: 0,
  26. loop: true,
  27. effect: 'fade',
  28. lazyLoading: true,
  29. // 解决点击分页器后图片就不能轮播的问题
  30. autoplayDisableOnInteraction: false,
  31. pagination: '.swiper-pagination',
  32. paginationClickable: true,
  33. paginationElement: 'li',
  34. prevButton: '.swiper-button-prev',
  35. nextButton: '.swiper-button-next'
  36. }
  37. // banners: {}
  38. }
  39. },
  40. // mounted () {
  41. // this.$http.get('/api/carousel/home%20page%20banner')
  42. // .then(response => {
  43. // this.banners = response.data
  44. // this.x++
  45. // })
  46. // }
  47. computed: {
  48. providerType () {
  49. return this.$route.path === '/provider/home' ? 'agency' : 'original'
  50. },
  51. banners () {
  52. if (this.$store.state.carousel.banners) {
  53. let banner = this.$store.state.carousel.banners.data.slice()
  54. banner.sort(function (a, b) {
  55. return a.orderNumber - b.orderNumber
  56. })
  57. return banner
  58. } else {
  59. return ''
  60. }
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. @import '~assets/scss/variables';
  67. $carousel_width: 910px;
  68. $carousel_width_670: 670px;
  69. $carousel_height: 358px;
  70. .carousel {
  71. &.width_670{
  72. width: $carousel_width_670;
  73. }
  74. width: $carousel_width;
  75. height: $carousel_height;
  76. transition: background-color .3s;
  77. position: relative;
  78. overflow: hidden;
  79. .swiper-wrapper {
  80. .swiper-slide {
  81. img {
  82. display: block;
  83. width: 100%;
  84. height: $carousel_height;
  85. }
  86. }
  87. }
  88. }
  89. </style>