Carousel.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div class="carousel">
  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.detailsLink" target="_blank">
  7. <img :src="banner.pictureLink">
  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. }
  25. },
  26. props: ['banners'],
  27. mixins: [carousel],
  28. computed: {
  29. storeType () {
  30. this.activeSlide = 0
  31. return this.$route.params.type
  32. },
  33. swiperOption () {
  34. return {
  35. autoplay: 5000,
  36. initialSlide: 0,
  37. loop: true,
  38. effect: this.effect,
  39. lazyLoading: true,
  40. // 解决点击分页器后图片就不能轮播的问题
  41. autoplayDisableOnInteraction: false,
  42. pagination: '.swiper-pagination',
  43. paginationClickable: true,
  44. paginationElement: 'li',
  45. prevButton: '.swiper-button-prev',
  46. nextButton: '.swiper-button-next'
  47. }
  48. }
  49. },
  50. created () {
  51. this.$store.dispatch('loadBanners', {type: this.storeType + '_banner_carousel'})
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. @import '~assets/scss/variables';
  57. $carousel_width: 955px;
  58. $carousel_height: 400px;
  59. .carousel {
  60. width: $carousel_width;
  61. height: $carousel_height;
  62. transition: background-color .3s;
  63. position: relative;
  64. overflow: hidden;
  65. .swiper-wrapper {
  66. .swiper-slide {
  67. img {
  68. display: block;
  69. width: 955px;
  70. height: $carousel_height;
  71. }
  72. }
  73. }
  74. }
  75. </style>