uni-app nvue在真机里使用swiper事件@animationfinish 无论如何detail.current都返回0

uni-app nvue在真机里使用swiper事件@animationfinish 无论如何detail.current都返回0

1 回复

更多关于uni-app nvue在真机里使用swiper事件@animationfinish 无论如何detail.current都返回0的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在真机调试中,[@animationfinish](/user/animationfinish) 事件返回的 detail.current 始终为 0,通常是由于事件绑定时机或组件状态问题导致的。以下是排查和解决步骤:

  1. 检查事件绑定时机:确保 swiper 组件在数据渲染完成后再绑定事件。若在 onLoad 中初始化数据,可在 onReadynextTick 中处理事件逻辑,避免数据未就绪时事件触发异常。

  2. 使用 $refs 获取实时索引:若事件参数不可靠,可通过 $refs 直接获取 swiper 实例的当前索引。例如:

    <swiper ref="swiperRef" [@animationfinish](/user/animationfinish)="handleAnimationFinish">
    

    在方法中:

    handleAnimationFinish() {
      const currentIndex = this.$refs.swiperRef.current;
      console.log('当前索引:', currentIndex);
    }
回到顶部