使用wx:if隐藏元素,值为false时获取不到宽高?怎么解决

小程序 文章 2021-03-10 10:21 394 0 全屏看文

AI助手支持GPT4.0

使用wx:if隐藏元素,值为false时获取不到宽高?怎么解决Use wx:if to hide the element, and the width and height cannot be obtained when the value is false? How to deal with it

使用wx:if隐藏元素,值为false时获取不到宽高?怎么解决

在开发的时候遇到这个问题,该元素一开始是通过wx:if值为false隐藏起来的,但是我想要获取它的高度,但获取不到,值为true才能获取到!

求怎么在值为false的时候获取到高度的方法!!!

如下:

获取结果:

如果值为true是可以获取到的

In the process of development, I encountered this problem. At the beginning, the element was hidden by Wx: if value is false, but I want to get its height, but I can't get it. Only when the value is true can I get it! How to get the height when the value is false!!! As follows: get the result: if the value is true, it can be obtained

回答:

Samuel.Schrödinger:

在框架中,使用 wx:if="" 来判断是否需要渲染该代码块

你都不渲染,怎么获取高度呢。

黑夜白昼:

不渲染,怎么获取高度呢

黑夜白昼:试试 hidden
|G.XIAO|:

wx:if,false 不会渲染,肯定取不到,需要换个方式

微盟:

用display:none代替wx:if隐藏元素试试

几点:

用hidden试一下行不行

默垂眸:

wx:if 换成hidden

Brother斌🎈:

要不获取成功后再在回调把它置为false

-EOF-

AI助手支持GPT4.0