当前位置:网站首页>【微信小程序】WXML模板语法-条件渲染
【微信小程序】WXML模板语法-条件渲染
2022-08-05 04:52: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
如果要一次性控制多个组件的展示和隐藏,可以使用 < block >
< /block >标签将多个组件包装起来:
<block wx:if={
{
true}}>
<view> view1 </view>
<view> view2 </view>
</block>
注意:< block >并不是一个组件,他只是一个容器,不会在页面种做任何渲染。
hidden
在小程序中,直接使用hidden="{ {condition}}"也能控制元素的显示和隐藏
<view hidden="{
{ condition }}">条件为true隐藏,条件为false显示</view>>
//condition需要在.js文件的data中定义
wx:if与hidden的区别
- 运行方式不同
- wx:if以动态创建和移除元素的方式
- hidden以切换样式的方式
- 使用建议:
- 频繁切换时,建议使用hidden
- 控制条件复杂,建议使用wx:if
边栏推荐
- 为什么刚考完PMP,就开始准备软考了?
- [BSidesCF 2019]Kookie
- Analyses the mainstream across technology solutions
- [MRCTF2020] PYWebsite
- The first performance test practice, there are "100 million" a little nervous
- [SWPU2019]Web1
- In the WebView page of the UI automation test App, the processing method when the search bar has no search button
- u-boot调试定位手段
- 数字孪生技术在电力系统中的应用现状
- No regrets, the appium automation environment is perfectly built
猜你喜欢

In the WebView page of the UI automation test App, the processing method when the search bar has no search button

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

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

Some conventional routines of program development (1)

creo怎么测量点到面的距离

请写出SparkSQL语句

LeetCode:1403. 非递增顺序的最小子序列【贪心】

Use IDEA to connect to TDengine server

App快速开发建设心得:小程序+自定义插件的重要性

概率论的学习和整理8: 几何分布和超几何分布
随机推荐
Excel画图
人性的弱点
JeeSite New Report
upload上传图片到腾讯云,如何上传图片
1068 Find More Coins
机器学习概述
uboot开启调试打印信息
【软考 系统架构设计师】软件架构设计③ 特定领域软件架构(DSSA)
特征预处理
u-boot debugging and positioning means
What is ASEMI photovoltaic diode, the role of photovoltaic diode
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
Cron(Crontab)--使用/教程/实例
作业8.4 进程间的通信 管道与信号
how to measure distance from point to face in creo
Paparazzi: Surface Editing by way of Multi-View Image Processing
Flutter学习-开篇
2023年信息与通信工程国际会议(JCICE 2023)
什么是ASEMI光伏二极管,光伏二极管的作用
NPDP证书含金量高吗?跟PMP相比?