vue中使用原生swiper

复制代码
<template>
    <div>
        <div class="swiper_Box" :class="identify">
            <div class="swiper-wrapper" :ref="identify">
                <div class="swiper-slide" v-for="(item,index) in imgArr" :key="'swiperSlide'+index">
                    <div class="bannerItem">
                        <img :src="item.url" alt="">
                    </div>
                </div>
            </div>
            <!-- <div v-if="imgArr.length>1" class="swiper-button-prev" slot="button-prev"></div>
            <div v-if="imgArr.length>1" class="swiper-button-next" slot="button-next"></div> -->
            <div class="swiper-pagination"></div>
        </div>
    </div>
</template>

<script>
export default {
    props:['imgArr','identify','paginationType'],//接收传来的轮播图
    watch:{
       imgArr:{
           handler(newVal){
               console.log(newVal)
           },
           immediate:true
       },
       identify:{
            handler(newVal){
                console.log("id:"+newVal)
                var self=this;
            },
           immediate:true 
       }
    },
    data(){
        return{
            swiperShow:false,
            MySwiper:null,//swiper实例
        }
    },
    created(){
    },
    mounted(){
        var self=this;
        self.MySwiper = new Swiper ('.'+self.identify,{
            init: true,
            observer:true,
            observeParents:true,
            slidesPerView: 1,
            spaceBetween: 0,
            keyboard: {
                enabled: true,
            },
            loop: true,
            autoplay: {
                delay: 8000,
                disableOnInteraction: false
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
                type:self.paginationType?self.paginationType:'bullets'
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev'
            },
        });
    }
}
</script>

<style scoped>
@import url("../styles/swiperBullet.css");
/* 轮播图 */
.swiperBox{
    width:100%;
}
.swiper_Box{
    position: relative;
    overflow: hidden;
}
.swiper_Box .bannerItem img{
    height:auto;
    width:100%;
}
.swiperBox .bannerItem{
    width:100%;
    text-align: center;
}
.swiperBox .bannerItem img{
    height:auto;
    width:100%;
}
.swiper-pagination{
    position: absolute;
    bottom:20px;
    left:50%;
    transform: translateX(-50%);
}

</style>
复制代码

swiper的引入形式是link标签引入样式

script标签引入js

posted @   古墩古墩  Views(700)  Comments(0Edit  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2019-01-13 js闭包的理解
2019-01-13 深入理解JS函数中this指针的指向
2019-01-13 es6数组去重
点击右上角即可分享
微信分享提示