当前位置:网站首页>[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
边栏推荐
- Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
- uboot开启调试打印信息
- University Physics---Particle Kinematics
- The difference between span tag and p
- UVA10827
- Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
- 作业8.4 进程间的通信 管道与信号
- 【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
- C language - vernacular to understand the original code, inverse code and complement code
- Flutter learning 5-integration-packaging-publish
猜你喜欢
【cesium】加载并定位 3D Tileset
Day019 Method overriding and introduction of related classes
for..in和for..of的区别
App rapid development and construction experience: the importance of small programs + custom plug-ins
机器学习概述
请写出SparkSQL语句
[BSidesCF 2019] Kookie
Develop your own node package
算法---一和零(Kotlin)
[cesium] 3D Tileset model is loaded and associated with the model tree
随机推荐
span标签和p标签的区别
MySQL Foundation (1) - Basic Cognition and Operation
phone call function
Day14 jenkins deployment
Homework 8.4 Interprocess Communication Pipes and Signals
[Nine Lectures on Backpacks - 01 Backpack Problems]
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
什么是ASEMI光伏二极管,光伏二极管的作用
LAB 信号量实现细节
uva1325
Flutter Learning 4 - Basic UI Components
为什么刚考完PMP,就开始准备软考了?
Flutter学习2-dart学习
Day14 jenkins部署
电话溥功能
Cron(Crontab)--使用/教程/实例
"Recursion" recursion concept and typical examples
Dephi reverse tool Dede exports function name MAP and imports it into IDA
Flutter学习5-集成-打包-发布
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)