Skip to content

Commit c91fdb4

Browse files
committed
fix: 兼容老版本
1 parent e7d71c7 commit c91fdb4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/packages/swiper/swiper.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,24 @@ export const Swiper = React.forwardRef<SwiperRef, Partial<WebSwiperProps>>(
101101
const runTimeSwiper = useCallback(() => {
102102
const durationNumber =
103103
typeof duration === 'string' ? parseInt(duration) : duration
104-
const d = typeof autoplay === 'number' ? autoplay : durationNumber
104+
let d = durationNumber
105+
// 优先使用明确设置的数值型自动播放间隔
106+
if (typeof props.autoPlay === 'number') {
107+
d = props.autoPlay
108+
} else if (typeof autoplay === 'number') {
109+
d = autoplay
110+
}
105111
timeoutRef.current = window.setTimeout(() => {
106112
next()
107113
runTimeSwiper()
108114
}, d)
109-
}, [autoplay, duration])
115+
}, [props.autoPlay, autoplay, duration])
110116

111117
useEffect(() => {
112-
if (!autoplay || dragging) return
118+
// 兼容旧版的 autoPlay 属性
119+
const shouldAutoplay = props.autoPlay || autoplay
120+
if (!shouldAutoplay || dragging) return
121+
// if (!autoplay || dragging) return
113122
runTimeSwiper()
114123
return () => {
115124
if (timeoutRef.current) window.clearTimeout(timeoutRef.current)

0 commit comments

Comments
 (0)