File tree 5 files changed +83
-7
lines changed
example/normal/uni_modules/zebra-swiper/components/z-swiper
5 files changed +83
-7
lines changed Original file line number Diff line number Diff line change @@ -196,10 +196,18 @@ Swiper 的初始启用状态。当 Swiper 被禁用时,它将隐藏所有导
196
196
## height
197
197
198
198
::: warning
199
- 设置swiper高度请使用` custom-style ` 。
199
+ 正常设置swiper高度请使用` custom-style ` 。
200
+
201
+ 单位为` px ` 。如果需要设置` rpx ` ,请通过` uni.rpx2px() ` 转换后再传给swiper。
202
+ :::
203
+
204
+ ::: tip
205
+ 在 ` popup ` 中使用 ` swiper ` 时,小程序与 H5 的弹窗加载机制存在显著差异。在小程序环境中,即使弹窗尚未显示,其内容在页面加载后仍会被预加载。这种情况下,通过 ` uni.createSelectorQuery() ` 方法获取宽高会返回 ` null ` 。
206
+
207
+ 为了应对这一问题,可以通过预设配置为 ` swiper ` 设置固定宽度,从而确保其正常显示和功能实现。
200
208
:::
201
209
202
- 强制设置swiper容器的高度。仅在隐藏时初始化swiper时才有用 。
210
+ 强制设置swiper容器的高度。仅在隐藏时初始化swiper时使用 。
203
211
204
212
<ComponentInfo type =" Number " value =" - " ></ComponentInfo >
205
213
@@ -275,10 +283,18 @@ Swiper 的初始启用状态。当 Swiper 被禁用时,它将隐藏所有导
275
283
## width
276
284
277
285
::: warning
278
- 设置swiper宽度请使用` custom-style ` 。
286
+ 正常设置swiper宽度请使用` custom-style ` 。
287
+
288
+ 单位为` px ` 。如果需要设置` rpx ` ,请通过` uni.rpx2px() ` 转换后再传给swiper。
289
+ :::
290
+
291
+ ::: tip
292
+ 在 ` popup ` 中使用 ` swiper ` 时,小程序与 H5 的弹窗加载机制存在显著差异。在小程序环境中,即使弹窗尚未显示,其内容在页面加载后仍会被预加载。这种情况下,通过 ` uni.createSelectorQuery() ` 方法获取宽高会返回 ` null ` 。
293
+
294
+ 为了应对这一问题,可以通过预设配置为 ` swiper ` 设置固定宽度,从而确保其正常显示和功能实现。
279
295
:::
280
296
281
- 强制设置swiper容器的宽度。仅在隐藏时初始化swiper时才有用 。
297
+ 强制设置swiper容器的宽度。仅在隐藏时初始化swiper时使用 。
282
298
283
299
<ComponentInfo type =" Number " value =" - " ></ComponentInfo >
284
300
Original file line number Diff line number Diff line change @@ -43,3 +43,13 @@ outline: deep
43
43
@use "@/uni_modules/zebra-swiper/modules/navigation/navigation.scss";
44
44
</style >
45
45
```
46
+
47
+ ## 小程序在弹窗 `popup` 中使用 `swiper` 时的加载问题 {#swiper-on-popup-error }
48
+
49
+ 在小程序和 H5 中,弹窗`v-show `的加载机制存在显著差异。
50
+
51
+ 小程序在页面加载时,即使弹窗未被显示,其内容也会被加载。然而,此时通过 `uni.createSelectorQuery()` 获取弹窗内容的宽高可能返回 `null`,导致 `swiper` 无法正常加载。
52
+
53
+ 为了解决这一问题,可以通过配置 `width` 或 `height` 属性,预先为 `swiper` 设置固定的宽高值,从而确保其正常加载和渲染。
54
+
55
+ 相关配置:[`width`](/api/basic#width ) | [`height`](/api/basic#height )
Original file line number Diff line number Diff line change @@ -436,6 +436,20 @@ onMounted(() => {
436
436
.catch ((error ) => {
437
437
console .error (error )
438
438
})
439
+ } else {
440
+ mountSwiper (
441
+ {
442
+ el: swiperElRef .value as unknown as HTMLElement ,
443
+ adapterEl: swiperElRef .value ,
444
+ nextEl: nextElRef .value ,
445
+ prevEl: prevElRef .value ,
446
+ paginationEl: paginationElRef .value ,
447
+ scrollbarEl: scrollbarElRef .value ,
448
+ swiper: swiperRef .value as unknown as SwiperInterface
449
+ },
450
+ swiperParams
451
+ )
452
+ emit (' swiper' , swiperRef .value )
439
453
}
440
454
}
441
455
})
Original file line number Diff line number Diff line change @@ -436,6 +436,20 @@ onMounted(() => {
436
436
.catch ((error ) => {
437
437
console .error (error )
438
438
})
439
+ } else {
440
+ mountSwiper (
441
+ {
442
+ el: swiperElRef .value as unknown as HTMLElement ,
443
+ adapterEl: swiperElRef .value ,
444
+ nextEl: nextElRef .value ,
445
+ prevEl: prevElRef .value ,
446
+ paginationEl: paginationElRef .value ,
447
+ scrollbarEl: scrollbarElRef .value ,
448
+ swiper: swiperRef .value as unknown as SwiperInterface
449
+ },
450
+ swiperParams
451
+ )
452
+ emit (' swiper' , swiperRef .value )
439
453
}
440
454
}
441
455
})
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<view class =" demo-swiper" >
3
3
<demo-block title =" normal" >
4
- <view class = " " >
5
- <z-swiper v-model:list = " virtualList " loop :modules =" modules" >
4
+ <view v-show = " showSwiper " >
5
+ <z-swiper :width = " swiperWidth " effect = " cube " :modules =" modules" >
6
6
<z-swiper-item v-for =" (item,index) in virtualList" :key =" item.id" >
7
7
<demo-item :item =" item" ></demo-item >
8
8
</z-swiper-item >
9
9
</z-swiper >
10
10
</view >
11
11
</demo-block >
12
+ <demo-block title =" normal" >
13
+ <view v-if =" showSwiperIf" >
14
+ <z-swiper v-model:list =" virtualListNative" loop :modules =" modules" >
15
+ <z-swiper-item v-for =" (item,index) in virtualListNative" :key =" item.id" >
16
+ <demo-item :item =" item" ></demo-item >
17
+ </z-swiper-item >
18
+ </z-swiper >
19
+ </view >
20
+ </demo-block >
12
21
</view >
13
22
</template >
14
23
15
24
<script setup>
16
25
import {
26
+ onMounted ,
17
27
ref ,
18
28
watch
19
29
} from ' vue'
42
52
]
43
53
const list = ref ([])
44
54
55
+ const showSwiper = ref (false )
56
+ const swiperWidth = ref (300 )
57
+
58
+ const showSwiperIf = ref (false )
59
+
60
+ onMounted (() => {
61
+ setTimeout (() => {
62
+ showSwiper .value = true
63
+ showSwiperIf .value = true
64
+ }, 2000 )
65
+ })
66
+
45
67
const virtualList = ref (
46
68
Array .from ({
47
69
length: 3
56
78
)
57
79
const virtualListNative = ref (
58
80
Array .from ({
59
- length: 1000
81
+ length: 3
60
82
}).map ((item , index ) => {
61
83
const randomValue = Math .floor (Math .random () * 7 )
62
84
return {
You can’t perform that action at this time.
0 commit comments