vue swiper FIG asynchronous loading carousel, and lazy loading

Handling from: https://blog.csdn.net/weixin_38304202/article/details/78282826

 

effect:

 

Installation is omitted here

 

view:

<div class="banner" v-show="isShowSlide">
        <div class="swiper-banner">
          <div class="swiper-wrapper">
               <div class="swiper-slide" v-for="(item,index) in swiperList" :key="index">
                    <img src="images//img_loading.jpg"
                :data-src="item.imgpath" class="swiper-lazy" style="width:100%;height:100%">
               </div>
          </div>
           <div class="swiper-pagination" v-if="swiperList.length>1">
                 <span v-for="(item,index) in swiperList"></span>
          </div>
        </div>
      </div>
getimgs: function () {// call the Created
        let _this = this;
        _this.axios.get('请求链接').then(function(res) {
          if (res.status === 200 && res.data.result === "0") {
            const data = res.data.message.list;
            for (let i in data) {
              _this.swiperList.push(data[i]);
            }
            _this.swiperLength = _this.swiperList.length;

            _this.$nextTick(function() {
              if (_this.swiperLength > 0) {
                _this.isShowSlide = true;
                if (_this.swiperLength == 1) {
                  _this.isAutoplay = 0;
                  _this.isLoop = false;
                } else {
                  _this.isAutoplay = 3000;
                  _this.isLoop = true;
                }
                _this.mySwiper = new Swiper(".swiper-banner", {
                  autoplay: _this.isAutoplay,
                  loop: _this.isLoop,
                  autoplayDisableOnInteraction: false,
                  preventLinksPropagation: false,
                  LazyLoading: to true , // lazy loading opening 
                  the pagination: 'the pagination-.swiper' ,
                  Observer: to true , // modifying Swiper or their sub-elements, the automatic initialization Swiper 
                  observeParents: to true , // modifying the parent element Swiper automatically initializes Swiper 
                })
              } else {
                _this.isShowSlide = false;
              }
            })
          } else {   
              _this.isShowSlide = false;            
          }
        }).catch(function(err) {
          console.log(err);
        })
      },
  .swiper-wrapper {
    font-size: 0;
  }

  .swiper-pagination {
    width: 100%;
    height: .2rem;
    text-align: center;
    position: absolute;
    bottom: 0 !important;
    line-height: .2rem;
    box-sizing: border-box;
    padding: 0 .3rem;
    font-size: 0;
  }

  >>>.swiper-pagination-bullet-active {
    background-color: #ff7035 !important;
    opacity: 1;
  }

  .swiper-pagination-bullet {
    background-color: rgba(255, 255, 255, 1);
    opacity: 1;
  }

  .swiper-slide {
    height: 1.5rem !important;
    line-height: 1.5rem !important;
  }

  .swiper-wrapper {
    width: 100% !important;
    height: 100% !important;
  }

  .swiper-container-autoheight,
  .swiper-container-autoheight .swiper-slide {
    height: 100%;
    font-size: 0;
    position: relative;
  }

 

Guess you like

Origin www.cnblogs.com/linjiangxian/p/11649860.html