Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

export default {
  data() {
    return {
      mySwiper
    };
  },
  mounted() {
    this.mySwiper = new Swiper(".swiper-container-slide", {
      noSwipingClass: "stop-swiping",
      pagination: {
        el: ".swiper-pagination",
        clickable: false,
        renderBullet: function(index, className) {
          return '<span class="' + className + '">' + (index + 1) + "</span>";
        }
      },
      navigation: {
        prevEl: ".swiper-button-prev",
        nextEl: ".swiper-button-next"
      },
      on: {
        reachEnd: () => {
          this.mySwiper.params.pagination.clickable = true; // 对 clickable 属性进行了修改,但失效
          console.log("到了最后一个slide");
        }
      }
    });
  }
};

我的预期效果是默认分页器无法点击,但当滚动到最后一页的时候,分页器方开启点击,经过如下尝试均以失败告终:

  • 尝试通过官方api this.mySwiper.params.pagination.clickable 方法,失效;
  • 尝试通过直接修改 data 方法,失效;
  • 尝试通过 watch 监视修改方法,失效;

还望指点,谢谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
520 views
Welcome To Ask or Share your Answers For Others

1 Answer

按照官网的案例,设置后需要重新初始化

//如果你在swiper初始化后才决定使用clickable,可以这样设置 
mySwiper.params.pagination.clickable = true ; 
//此外还需要重新初始化pagination 
mySwiper.pagination.destroy()
mySwiper.pagination.init()
mySwiper.pagination.bullets.eq(0).addClass('swiper-pagination-bullet-active');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...