Home >WeChat Applet >Mini Program Development >Detailed introduction to conditional rendering of WeChat mini program
This article mainly introduces relevant information on the detailed explanation of conditional rendering of WeChat mini programs. Friends who need it can refer to
1, wx.if
In WeChat mini programs, mini programs Use wx.if="{{condition}}" to determine whether to render the code block. The usage is as follows:
You can also use wx.elif and wx.else to add an else block, for example:
2, block wx:if
wx:if is a control attribute and needs to be added to the label, but if we want to judge multiple labels at once, I can use < ;block/>Wrap multiple components and use wx:if control attributes on them.
It is not a component, it is just a wrapping element and will not do any rendering on the page. Only control attributes are accepted. Examples are as follows:
Note: Generally speaking, wx:if has a higher switching cost and hidden has a higher initial rendering cost. Therefore, if frequent switching is required, it is better to use hidden. If the conditions are unlikely to change during runtime, wx:if is better.
Thank you for reading, I hope it can help you, thank you for your support of this site!
The above is the detailed content of Detailed introduction to conditional rendering of WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!