Skip to content

Commit 6a14879

Browse files
docs: ✏️ 增加关于微信小程序v-if和slot执行顺序异常问题的介绍
1 parent fc3e4ef commit 6a14879

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/guide/common-problems.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,34 @@ const toast = useToast()
239239
const myToast = useToast({ selector: 'my-toast' })
240240
```
241241

242+
## 为什么在微信小程序上使用`Popup``ActionSheet``DropDownItem`等弹出框组件包裹`Slider``Tabs`等组件时,`Slider``Tabs`表现异常?
243+
244+
目前uni-app使用`v-if`控制插槽是否显示编译到微信小程序端存在问题,具体可以参考issue:[4755](https://github.com/dcloudio/uni-app/issues/4755)[4847](https://github.com/dcloudio/uni-app/issues/4847)。而`Popup``ActionSheet``DropDownItem`恰好正是使用`v-if`控制插槽是否显示,所以会导致`Slider``Tabs`在未渲染时执行了相关生命周期。`Slider``Tabs`等组件的一些数据如`Slider`的宽度,`Tabs`的滑块位置等会在onMounted等生命周期进行获取,此时这些数据将会存在异常。
245+
246+
解决办法:
247+
248+
1.`Slider``Tabs`等组件外部使用`v-if`控制弹框打开前不展示,例如:
249+
250+
```html
251+
<wd-slider v-if="showSlider"></wd-slider>
252+
```
253+
254+
1.`Popup``ActionSheet``DropDownItem`等组件完全打开时的钩子中重新初始化`Slider``Tabs`组件,例如:
255+
256+
```html
257+
<wd-popup v-model="show" position="bottom" closable custom-style="height: 200px;" @after-enter="handleOpened">
258+
<wd-slider v-model="value" ref="slider"></wd-slider>
259+
</wd-popup>
260+
```
261+
```ts
262+
const slider = ref()
263+
264+
function handleOpened() {
265+
slider.value!.initSlider()
266+
}
267+
268+
```
269+
242270
## 如何快速解决你的问题?
243271

244272
[提问的智慧](https://lug.ustc.edu.cn/wiki/doc/smart-questions/),可以帮助你快速提出正确的问题,获得更快的解答。

0 commit comments

Comments
 (0)