【问题标题】:Swiperjs slides wont slide properlySwiper Js 幻灯片无法正确滑动
【发布时间】:2021-12-30 16:07:36
【问题描述】:

我正在使用 swiperjs,但我在制作幻灯片时遇到了困难 因为他们不会捕捉到下一张幻灯片,我无法从他们那里获得活动索引这是我的代码
我在哪里出错了我在 ionic 框架中使用 typescript 和 swiperjs 6.84 版

import 'swiper/components/navigation/navigation.min.css'
import 'swiper/components/pagination/pagination.min.css'






  const pagination = {
    clickable: true,
  };
 
  return (
    <IonPage>
  

      <Swiper
        pagination={pagination}
        
        onBeforeSlideChangeStart={e => {
          setIndex(e.activeIndex)
        }}>
        <SwiperSlide >
          <item property={property} index={0} save={dispatch} activeIndex={index} />
        </SwiperSlide>
        <SwiperSlide >
            <item 2 property={property} index={1} />
        </SwiperSlide>
        <SwiperSlide >
            <item3 property={property} index={1} />
        </SwiperSlide>
      </Swiper>
      <IonButton
        disabled={true}
        onClick={(e) => {
          e.preventDefault();
        }}
        className={"next"}
        expand={"block"}
      >
        Save
      </IonButton>
    </IonPage>
  );
}

【问题讨论】:

标签: javascript reactjs typescript ionic-framework swiperjs


【解决方案1】:

我忘了添加 ionContent,所以幻灯片没有以正确的方式做出反应,我还必须添加观察

 <IonPage>
  
<IonContent fullscreen>
      <Swiper
        pagination={pagination}
        observeParents={true}
        observer={true}
        onBeforeSlideChangeStart={e => {
          setIndex(e.activeIndex)
        }}>
        <SwiperSlide >
          <item property={property} index={0} save={dispatch} activeIndex={index} />
        </SwiperSlide>
        <SwiperSlide >
            <item 2 property={property} index={1} />
        </SwiperSlide>
        <SwiperSlide >
            <item3 property={property} index={1} />
        </SwiperSlide>
      </Swiper>
      <IonButton
        disabled={true}
        onClick={(e) => {
          e.preventDefault();
        }}
        className={"next"}
        expand={"block"}
      >
        Save
      </IonButton>
</IonContent>
    </IonPage>

【讨论】:

  • 你不需要任何观察者代码...我会删除它,以免其他看到此解决方案的人感到困惑
  • 我使用的是 6.84 版本,我的个人解决方案没有它就无法工作@AaronSaunders,但感谢您为其他可能对我有不同代码的人提供的清晰说明
猜你喜欢
  • 2022-12-21
  • 2019-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-06
  • 2019-09-06
  • 2020-06-30
相关资源
最近更新 更多