当前位置:网站首页>[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
边栏推荐
- Flutter Learning 4 - Basic UI Components
- number_gets the specified number of decimals
- Flutter learning 2-dart learning
- u-boot debugging and positioning means
- 【cesium】加载并定位 3D Tileset
- The difference between span tag and p
- Reverse theory knowledge 4
- span标签和p标签的区别
- dedecms dream weaving tag tag does not support capital letters fix
- 【学习笔记之菜Dog学C】动态内存管理之经典笔试题
猜你喜欢

关于sklearn库的安装

Please write the SparkSQL statement

结构光三维重建(二)线结构光三维重建

ESP32 485光照度

狗仔队:表面编辑多视点图像处理

Feature preprocessing

App rapid development and construction experience: the importance of small programs + custom plug-ins

MySQL基础(一)---基础认知及操作

upload upload pictures to Tencent cloud, how to upload pictures

Flutter learning three-Flutter basic structure and principle
随机推荐
WPF中DataContext作用
The solution to the failure to read channel information when dedecms generates a message in the background
uboot enable debug printing information
Develop your own node package
机器学习概述
How to quickly upgrade your Taobao account to a higher level
动力小帆船制作方法简单,电动小帆船制作方法
逆向理论知识4
重新审视分布式系统:永远不会有完美的一致性方案……
JeeSite New Report
entry point injection
How to deal with DNS hijacking?
span标签和p标签的区别
The log causes these pits in the thread block, you have to guard against
2023年信息与通信工程国际会议(JCICE 2023)
【无标题】
【cesium】Load and locate 3D Tileset
Machine Learning Overview
App快速开发建设心得:小程序+自定义插件的重要性
dedecms织梦tag标签不支持大写字母修复