1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <template>
- <div class="carousel">
- <div v-swiper:mySwiper="swiperOption">
- <div class="swiper-wrapper">
- <div class="swiper-slide" v-for="banner in banners">
- <a :href="banner.detailsLink" target="_blank">
- <img :src="banner.pictureLink">
- </a>
- </div>
- </div>
- <div class="swiper-pagination swiper-pagination-bullets"></div>
- <div class="swiper-button-prev"><i class="iconfont icon-arrow-left"></i></div>
- <div class="swiper-button-next"><i class="iconfont icon-arrow-right"></i></div>
- </div>
- </div>
- </template>
- <script>
- import { carousel } from '~utils/mixin'
- export default {
- name: 'carousel',
- data () {
- return {
- activeSlide: 0
- }
- },
- props: ['banners'],
- mixins: [carousel],
- computed: {
- storeType () {
- this.activeSlide = 0
- return this.$route.params.type
- },
- swiperOption () {
- return {
- autoplay: 5000,
- initialSlide: 0,
- loop: true,
- effect: this.effect,
- lazyLoading: true,
- observer: true,
- // 解决点击分页器后图片就不能轮播的问题
- autoplayDisableOnInteraction: false,
- pagination: '.swiper-pagination',
- paginationClickable: true,
- paginationElement: 'li',
- prevButton: '.swiper-button-prev',
- nextButton: '.swiper-button-next'
- }
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.mySwiper.update()
- // this.mySwiper.slideTo(0, 500, true)
- // alert(this.mySwiper.activeIndex)
- })
- },
- created () {
- this.$store.dispatch('loadBanners', {type: this.storeType + '_banner_carousel'})
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~assets/scss/variables';
- $carousel_width: 955px;
- $carousel_height: 400px;
- .carousel {
- width: $carousel_width;
- height: $carousel_height;
- transition: background-color .3s;
- position: relative;
- overflow: hidden;
- .swiper-wrapper {
- .swiper-slide {
- img {
- display: block;
- width: 955px;
- height: $carousel_height;
- }
- }
- }
- }
- </style>
|