reactjs - 将事件幻灯片设置为 swiper/react with react 状态

标签 reactjs swiper

我想问一下有没有办法用swiper/react来控制/设置事件幻灯片?
我试图用 Prop 处理 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>
  )
}

关于reactjs - 将事件幻灯片设置为 swiper/react with react 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65006220/

相关文章:

javascript - 通过在没有前端渲染部分的情况下登录控制台来 react redux 测试

css - 带左/右箭头的 slider

reactjs - 如何在不使用固定 CSS 的情况下更改 React JS 中的 Swiper 高度或滑动宽度

list - Flutter/Dart-如何在flutter_Swiper包中使用onPressed和flatButton播放列表中的声音?

javascript - 滑动滑动显示垂直但水平工作

node.js - 为什么 Socket.io 轮询请求不断收到 404 错误?

javascript - 如果新状态 React 中缺少默认状态值,则保留默认状态值

javascript - Flow : What is the equivalent of PropTypes. 流中的函数?

javascript - React JS 根据用户输入显示月份

slider - Swiper 触摸事件 - 启用点击但禁用拖动