Vue中利用swiper实现自动轮播功能

40 篇文章 0 订阅
21 篇文章 0 订阅

前端工作中轮播图是必不可少的,最近一个项目需要在vue项目中插入轮播图,很多条数据显示n个,自动向上滚动,无缝连接,以前用过很多次swiper轮播插件,所以立马上手,以为手到擒来,结果。。。

异步获取数据后初始化swiper

new Vue({
                 el: "#networkWarningCounts",
                 data: {
                     items: [],
                     mySwiper: null
                },
                 mounted : function () {
                     this. getList();
                },
                 methods: {
                     getList : function () {
                         var that = this;
                         $. ajax({
                             url: "http://39.104.99.77:8080/brand/selectList",
                             type: 'get',
                             dataType: 'json',
                             success : function ( data) {
                                 console. log( data);
                                 that. items = data. data;
                                 that. $nextTick( function () {
                                     that. initSwiper();
                                })
                            }
                        });
                    },
                     initSwiper : function () {
                             var that = this;
                             this. mySwiper = new Swiper( '.swiper-container', {
                                 direction: 'vertical',
                                 loop: true,
                                 slidesPerView: 5,
                                 spaceBetween: 0,
                                 observer: true, //修改swiper自己或子元素时,自动初始化swiper
                                 observeParents: false,
                                 paginationClickable: true,
                                 autoplay: 1000,
                            })
                    }
                }
            })

注意:autoplay


Swiper3和Swiper4的区别,如果在4中autoplay:true,3中需要设置具体的时间毫秒

提示:看api要看相对应版本的,以免出错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值