Carousel.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. observer: true,
  41. // 解决点击分页器后图片就不能轮播的问题
  42. autoplayDisableOnInteraction: false,
  43. pagination: '.swiper-pagination',
  44. paginationClickable: true,
  45. paginationElement: 'li',
  46. prevButton: '.swiper-button-prev',
  47. nextButton: '.swiper-button-next'
  48. }
  49. }
  50. },
  51. mounted() {
  52. this.$nextTick(() => {
  53. this.mySwiper.update()
  54. // this.mySwiper.slideTo(0, 500, true)
  55. // alert(this.mySwiper.activeIndex)
  56. })
  57. },
  58. created () {
  59. this.$store.dispatch('loadBanners', {type: this.storeType + '_banner_carousel'})
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. @import '~assets/scss/variables';
  65. $carousel_width: 955px;
  66. $carousel_height: 400px;
  67. .carousel {
  68. width: $carousel_width;
  69. height: $carousel_height;
  70. transition: background-color .3s;
  71. position: relative;
  72. overflow: hidden;
  73. .swiper-wrapper {
  74. .swiper-slide {
  75. img {
  76. display: block;
  77. width: 955px;
  78. height: $carousel_height;
  79. }
  80. }
  81. }
  82. }
  83. </style>