search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Tutorial Conditional Rendering

Conditional rendering

The so-called conditional rendering refers to the logical value of the data binding expression to determine whether to render the current component. In the following piece of code, there is a piece of code that uses the hidden attribute:

<view class=&#39;content&#39; hidden=&#39;{{flag ? true: false}}&#39;>
    <text>{{hiddencontent}}</text>
 </view>

In the above barcode, when the value of the flag variable is true, the view component and the included components will not be rendered. When the flag variable When the value is false, the view component output is rendered to the page.

wx:if conditional rendering

In the WeChat applet wxml file, another way to perform similar conditional rendering is to use the wx:if attribute to control the current component. The code is as follows:

<view wx:if= &#39;{{condition}}&#39;>内容</view>

In the above code, when the value of the condition variable is true, the view component will render the output. When the condition variable is false, the view component will not render.

In our opinion, the wx:if attribute is similar to the hidden component. The difference is that the logical variables that control whether to render are opposite. However, wx:if can be used for more convenient control. You can use wx:if ,wx:else to add multiple branch code blocks. If the value of the control expression is true, one branch will be rendered, and if it is false, another branch will be rendered. Please see the code:

<view wx:if= &#39;{{length > 3}}&#39;>内容1</view>
<view wx:elif= &#39;{{length < 5}}&#39;>内容2</view>
<view wx:else&#39;>内容3</view>

In the above code, when length If the value is greater than 3, content 1 is rendered. When the value of length is greater than 3 and less than 5, the interface renders and outputs content 2. If none of the above conditions are met, content 3 is rendered.

Smartness depends on hard work, and knowledge depends on daily accumulation

The above is the detailed content of WeChat Mini Program Tutorial Conditional Rendering. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor