vue-awesome-swiper

效果: 鼠标拖动, 自动上下滚动

在这里插入图片描述

使用,awesome-swiper是基于swiper, 需要下载两个插件: 注意版本:
 "swiper": "4.5.1",
 "vue-awesome-swiper": "3.1.3",
效果实现 思路:

将接口数据修改成二维数组:

  getHonor() {
      this.$apis.volunteer.getHonor({  }).then(({ data }) => {
        var len = data.list.length
        var arr = []
        for (var i = 0; i < len; i += 4) {
          arr.push(data.list.slice(i, i + 4))
        }
        this.honorList = arr
        this.$nextTick(() => {
          this.swiperOption.loopAdditionalSlides = this.honorList.length
          this.swiperOption.autoplay = this.honorList.length > 3
          // this.swiper.update(true)
        })
      })
    },
swiper 配置:
  swiperOption: {
        direction: 'vertical',
        loopAdditionalSlides: 3,
        observer: true,
        // 修改swiper自己或子元素时,自动初始化swiper
        observeParents: true,
        // 修改swiper的父元素时,自动初始化swiper
        autoplay: true,
        loop: true,
        height: 120,
        speed: 4000,
        resize: () => {
          this.swiper.params.height = document.documentElement.getElementsByClassName(
            'mans'
          )[0].offsetHeight
          this.swiper.update(true)
        }
      }
后台数据,动态修改loopAdditionalSlides 属性, autoplay属性

loopAdditionalSlides :决定循环产生几行(swiper API)
autoPLay: 如果接口数据超出12组, 大于三行,需要自动滚动

  this.$nextTick(() => {
          this.swiperOption.loopAdditionalSlides = this.honorList.length
          this.swiperOption.autoplay = this.honorList.length > 3
          // this.swiper.update(true)
        })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值