当前位置:网站首页>[WeChat applet] WXML template syntax - conditional rendering
[WeChat applet] WXML template syntax - conditional rendering
2022-08-05 05:03:00 【m0_65431212】
wx:if
在小程序中,使用 wx:if=“{ {condiion}}” 来判断是否需要渲染该代码块:
<view wx:if="{
{condiion}}"> true </view>
也可以用 wx:elif 和 wx:else 来添加 else 判断:
<view wx:if="{
{type ===1}}"> 男 </view>
<view wx:elif="{
{type ===2}}"> 女 </view>
<view wx:else> 保密 </view>
并在,js文件中定义type的值
data: {
type: 1
},
结合 < block > 包装 wx::if
如果要Control the show and hide of multiple components at once,可以使用 < block >
< /block >标签Wrap up multiple components:
<block wx:if={
{
true}}>
<view> view1 </view>
<view> view2 </view>
</block>
注意:< block >并不是一个组件,he is just a container,Does not do any rendering on the page.
hidden
在小程序中,直接使用hidden="{ {condition}}"Show and hide elements can also be controlled
<view hidden="{
{ condition }}">条件为true隐藏,条件为false显示</view>>
//condition需要在.js文件的data中定义
wx:if与hidden的区别
- 运行方式不同
- wx:if以动态创建和移除元素的方式
- hidden以切换样式的方式
- 使用建议:
- 频繁切换时,建议使用hidden
- 控制条件复杂,建议使用wx:if
边栏推荐
- The difference between span tag and p
- Bytebuffer put flip compact clear method demonstration
- The log causes these pits in the thread block, you have to guard against
- Detailed explanation of Mysql's undo log
- mysql数据库表什么字段类型的存储长度最大?
- uboot开启调试打印信息
- Feature preprocessing
- 虚证、实证如何鉴别?
- Flutter学习5-集成-打包-发布
- 什么是ASEMI光伏二极管,光伏二极管的作用
猜你喜欢
dedecms后台生成提示读取频道信息失败的解决方法
Flutter learning 5-integration-packaging-publish
二叉树基本性质+oj题解析
Flutter学习三-Flutter基本结构和原理
使用IDEA连接TDengine服务器
Machine Learning Overview
LeetCode:1403. 非递增顺序的最小子序列【贪心】
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
Structured light 3D reconstruction (1) Striped structured light 3D reconstruction
Mini Program_Dynamic setting of tabBar theme skin
随机推荐
JeeSite New Report
how to measure distance from point to face in creo
结构光三维重建(二)线结构光三维重建
LAB Semaphore Implementation Details
Cron(Crontab)--使用/教程/实例
Flutter学习5-集成-打包-发布
University Physics---Particle Kinematics
Develop your own node package
【informix】解决启动报错大全,以及解决办法
WPF中DataContext作用
The difference between span tag and p
大学物理---质点运动学
Flutter learning - the beginning
How can Flutter parent and child components receive click events
uboot开启调试打印信息
[cesium] 3D Tileset model is loaded and associated with the model tree
uboot enable debug printing information
Application status of digital twin technology in power system
Shell(4)条件控制语句
Bytebuffer put flip compact clear method demonstration