reactjs - 将活动幻灯片设置为 swiper/react 与反应状态
问题描述
我想问一下是否有办法用 swiper/react 控制/设置活动幻灯片?
我尝试使用道具处理 onSwiper 函数,但仍然无法更新幻灯片索引。
谢谢
解决方案
您可以使用 swiper 实例访问 swiper API ( https://swiperjs.com/api/ ) 并且有方法slideTo
。
所以在代码示例中它看起来像这样
const App = () => {
// store swiper instance
const [swiper, setSwiper] = useState(null);
const slideTo = (index) => swiper.slideTo(index);
return (
<Swiper onSwiper={setSwiper} >
{/* ... */}
</Swiper>
)
}
推荐阅读
- ios - 可以在 Mac OSX 中使用网络扩展创建多个 Ikev2 VPN 吗?
- autohotkey - 检测操纵杆按钮
- javascript - Await 不是在等待 promise 解决
- sql - 如何在 LATERAL VIEW EXPLODE 中使数组动态化?
- javascript - 如何获取包含值数组的嵌套对象的值
- node.js - MongoParseError:在 Heroku 上部署应用程序时,URI 没有主机名、域名和 tld
- javascript - How to match 2 separate numbers in Javascript
- node.js - 在 Lambda 函数中使用 axios 时根据先前的请求设置 cookie
- java - 具有状态 Groovy / Java 的方法
- flutter - MediaQuery 导致整个应用程序消失 Flutter