Conditional rendering for WeChat mini-app tutorials and Wechat mini-app Rendering

Source: Internet
Author: User

Conditional rendering for mini-program tutorials

Series of articles:

Mini-program tutorial-WXSS
References to mini-program tutorials
Events of mini-program tutorials
Small Program tutorial Template
List rendering of Applet tutorials
Conditional rendering of mini-program tutorials
Data Binding in applet tutorial
Mini-program tutorial-WXML

Wx: if

In MINA, we use wx: if = "{condition}" to determine whether to render the code block:

<View wx: if = "{condition}"> True </view>

You can also use wx: elif and wx: else to add an else block:

<view wx:if="{{length > 5}}"> 1 </view><view wx:elif="{{length > 2}}"> 2 </view><view wx:else> 3 </view>

Block wx: if

Because wx: if is a control attribute, you need to add it to a tag. However, if we want to determine multiple component labels at a time, we can use one <block/> label to wrap multiple components and use wx: if to control the attributes above.

<block wx:if="{{true}}"> <view> view1 </view> <view> view2 </view></block>

Note: <block/> is not a component. It is only a packaging element. It does not make any rendering on the page and only accepts control attributes.

Wx: if vs hidden

Because the template in wx: if may also contain data binding, MINA has a partial rendering process when the conditional values of wx: if are switched, it will make sure that the condition block is destroyed or re-rendered when switching.

At the same time, wx: if is also inert. if the initial rendering condition is false, MINA does nothing and starts partial rendering only when the condition is changed to true for the first time.

In contrast, hidden is much simpler, and components are always rendered, just simple control of display and hiding.

In general, wx: if has higher switching consumption, while hidden has higher initial rendering consumption. Therefore, if frequent switchover is required, it is better to use den. if the running condition is unlikely to change, wx: if is better.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.