如何在 React 的 Ionic 5 中锁定幻灯片
How to lock slides in Ionic 5 in React
我不知道如何在第一个 IonSlide 中锁定幻灯片。我在网上没有找到解释。
const Slider: React.FC = () => {
return(
<IonApp>
<IonContent >
<IonSlides>
<IonSlide >
...
</IonSlide>
<IonSlide>
...
</IonSlide>
</IonSlides>
</IonContent>
</IonApp>
)
}
看看 useRef Hook. You can get a reference to your ion-slides
element and call the lockSwipes
method after the Swiper initialization using the ionSlidesDidLoad
事件:
import React, { useRef } from 'react';
const Slider: React.FC = () => {
const slidesEl = useRef(document.createElement('ion-slides'))
const handleSlidesLoad = () => {
slidesEl.current.lockSwipes(true)
}
return (
<IonApp>
<IonContent>
<IonSlides onIonSlidesDidLoad={() => handleSlidesLoad()} ref={slidesEl}>
<IonSlide>
...
</IonSlide>
<IonSlide>
...
</IonSlide>
</IonSlides>
</IonContent>
</IonApp>
)
}
我不知道如何在第一个 IonSlide 中锁定幻灯片。我在网上没有找到解释。
const Slider: React.FC = () => {
return(
<IonApp>
<IonContent >
<IonSlides>
<IonSlide >
...
</IonSlide>
<IonSlide>
...
</IonSlide>
</IonSlides>
</IonContent>
</IonApp>
)
}
看看 useRef Hook. You can get a reference to your ion-slides
element and call the lockSwipes
method after the Swiper initialization using the ionSlidesDidLoad
事件:
import React, { useRef } from 'react';
const Slider: React.FC = () => {
const slidesEl = useRef(document.createElement('ion-slides'))
const handleSlidesLoad = () => {
slidesEl.current.lockSwipes(true)
}
return (
<IonApp>
<IonContent>
<IonSlides onIonSlidesDidLoad={() => handleSlidesLoad()} ref={slidesEl}>
<IonSlide>
...
</IonSlide>
<IonSlide>
...
</IonSlide>
</IonSlides>
</IonContent>
</IonApp>
)
}