当前位置:网站首页>【微信小程序】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
边栏推荐
- ansible各个模块详解
- [MRCTF2020]Ezpop(详解)
- What is ASEMI photovoltaic diode, the role of photovoltaic diode
- Bytebuffer put flip compact clear method demonstration
- Please write the SparkSQL statement
- dedecms dream weaving tag tag does not support capital letters fix
- WPF中DataContext作用
- In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
- MySQL中控制导出文件后变为了\N有什么解决方案吗?
- App快速开发建设心得:小程序+自定义插件的重要性
猜你喜欢
[MRCTF2020]Ezpop(详解)
概率论的学习和整理8: 几何分布和超几何分布
Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
upload upload pictures to Tencent cloud, how to upload pictures
Use IDEA to connect to TDengine server
App rapid development and construction experience: the importance of small programs + custom plug-ins
Dephi reverse tool Dede exports function name MAP and imports it into IDA
Flutter学习2-dart学习
Feature preprocessing
Day019 方法重写与相关类的介绍
随机推荐
【软考 系统架构设计师】软件架构设计③ 特定领域软件架构(DSSA)
Develop your own node package
How to deal with DNS hijacking?
说说数据治理中常见的20个问题
Flutter Learning 4 - Basic UI Components
Excel画图
What is ASEMI photovoltaic diode, the role of photovoltaic diode
小程序_动态设置tabBar主题皮肤
[CISCN2019 South China Division]Web11
mysql数据库表什么字段类型的存储长度最大?
Is the NPDP certificate high in gold content?Compared to PMP?
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
虚证、实证如何鉴别?
【学习笔记之菜Dog学C】动态内存管理之经典笔试题
write the story about us
作业8.4 进程间的通信 管道与信号
Mysql的undo log详解
LeetCode:1403. 非递增顺序的最小子序列【贪心】
Visibility of multi-column attribute column elements: display, visibility, opacity, vertical alignment: vertical-align, z-index The larger it is, the more it will be displayed on the upper layer
Use IDEA to connect to TDengine server