Swiper组件跳到指定页实现的坑

hm688c71f046500
发布于 2025-9-28 15:02
浏览
0收藏

有需求让Swiper组件跳到指定页

官方文档给到的代码是这样的

首先定义一个 Swiper controller

private controller: SwiperController = new SwiperController();

该controller在swiper组件作为入参数带入

this.controller.showIndex(index) 这个方法显示没作用

Swiper(this.controller){
   //省略业务代码
   ...
   Button(()=>{

   })
   .onClick(()=>{
       this.controller.showIndex(index)
   })
}

需要使用这个方法才能跳到正确的页面

.index(this.currentIndex) 

Swiper(this.controller){
 
  Button(()=>{
      //....
  }).onClick(()=>{
       this.currentIndex = index
  )
}.index(this.currentIndex)

分类
标签
收藏
回复
举报
回复
    相关推荐