【问题标题】:How to destroy Swiper slider for VueJS如何销毁 VueJS 的 Swiper 滑块
【发布时间】:2017-03-22 06:43:55
【问题描述】:

我需要销毁 Swiper 滑块。
此代码初始化滑块

<script>
  import { swiper, swiperSlide } from 'vue-awesome-swiper';

  export default {
    components: {
      swiper,
      swiperSlide,
    },
    data() {
      return {
        swiperOption: {
          autoplay: false,
          spaceBetween: 20,
          pagination: '.swiper-pagination',
          paginationClickable: true,
        },
      };
    },
  };
</script>

如果窗口宽度发生变化,如何销毁滑块?
谢谢!

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component swiper


    【解决方案1】:

    您可以在resize 上添加eventListner,如下所示,destroySwiper 可以是处理您如何销毁滑动滑块的逻辑的方法:

    ready: function () {
      window.addEventListener('resize', this.destroySwiper)
    },
    beforeDestroy: function () {
      window.removeEventListener('resize', this.destroySwiper)
    }
    

    【讨论】:

    • 感谢您的回答,但 swiper 有销毁方法,我需要调用它。例如,我尝试 mount() { this.$children[0].destroy(); }, 但是方法destroy是未定义的或者不是函数
    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 2018-07-17
    • 2019-03-04
    • 1970-01-01
    • 2017-11-30
    相关资源
    最近更新 更多