File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,34 @@ const toast = useToast()
239239const 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/ ) ,可以帮助你快速提出正确的问题,获得更快的解答。
You can’t perform that action at this time.
0 commit comments