当前位置:网站首页>[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
边栏推荐
- 2023年信息与通信工程国际会议(JCICE 2023)
- How does the Flutter TapGestureRecognizer work
- software management rpm
- [BJDCTF2020] EasySearch
- 类的底层机制
- [BSidesCF 2019] Kookie
- number_gets the specified number of decimals
- The first performance test practice, there are "100 million" a little nervous
- 说说数据治理中常见的20个问题
- Flutter真机运行及模拟器运行
猜你喜欢

大学物理---质点运动学

ansible各个模块详解

The solution to the failure to read channel information when dedecms generates a message in the background

数字孪生技术在电力系统中的应用现状

Application status of digital twin technology in power system

『递归』递归概念与典型实例

There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space

dedecms后台生成提示读取频道信息失败的解决方法
虚证、实证如何鉴别?

The production method of the powered small sailboat is simple, the production method of the electric small sailboat
随机推荐
LAB 信号量实现细节
Analyses the mainstream across technology solutions
Day019 方法重写与相关类的介绍
Is the NPDP certificate high in gold content?Compared to PMP?
MySQL中控制导出文件后变为了\N有什么解决方案吗?
Dephi逆向工具Dede导出函数名MAP导入到IDA中
延迟加载js方式async与defer区别
请写出SparkSQL语句
机器学习概述
write the story about us
phone call function
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
Why did you start preparing for the soft exam just after the PMP exam?
Talk about 20 common problems in data governance
结构光三维重建(二)线结构光三维重建
淘宝账号如何快速提升到更高等级
[cesium] 3D Tileset model is loaded and associated with the model tree
Day019 Method overriding and introduction of related classes
特征预处理