vue-awesome-swiper的使用

1.安装
建议使用淘宝镜像,使用npm安装容易卡顿出错。

cnpm install vue-awesome-swiper@2.6.7 --save

2.在main.js中添加

import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper, /* { default global options } */)

3.轮播图组件

<template>
    <div class="wrapper">
        <swiper :options="swiperOption">
            <swiper-slide v-for="item in swiperList" :key="item.id">
                <img class="swiper-image" :src="item.imgUrl" alt="">
            </swiper-slide>
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
    name: 'HomeSwiper',
    data () {
        return {
            swiperOption: {
                pagination: '.swiper-pagination', // 点
                loop: true //开启循环轮播
            },
            swiperList: [{
                id: '0001',
                imgUrl: 'https://s10.mogucdn.com/mlcdn/c45406/190909_39ebb23kl541d368jj5eb1eadge05_1125x390.jpg'
            }, {
                id: '0002',
                imgUrl: 'https://s10.mogucdn.com/mlcdn/c45406/190909_7c5d93c9gkejj24ihlhibih16bkf9_1125x390.jpg'
            }]
        }
    }
}
</script>

<style lang="scss" scoped>
// 样式穿透:让.wrapper中所有的XX子组件样式都变为白色
.wrapper >>> .swiper-pagination-bullet-active{
    background:#fff !important;
}
.wrapper{
    //为防止图片加载完才撑开高度,设置宽度100%,高度会相对与款冬自动撑开34.66%
    padding-bottom:34.66%;
    width:100%;
    height:0;
    overflow: hidden;
    background:#eee;
    .swiper-image{
        width:100%;
    }
}
    
</style>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值