当前位置:网站首页>[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
边栏推荐
猜你喜欢
随机推荐
Shell(4) Conditional Control Statement
基于Web的商城后台管理系统的设计与实现
为什么刚考完PMP,就开始准备软考了?
Flutter学习5-集成-打包-发布
MySQL Foundation (1) - Basic Cognition and Operation
Please write the SparkSQL statement
雷克萨斯lm的安全性到底体现在哪里?一起来看看吧
Flutter TapGestureRecognizer 如何工作
电话溥功能
Bytebuffer put flip compact clear method demonstration
Flutter learning 2-dart learning
[cesium] 3D Tileset model is loaded and associated with the model tree
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
8.04 Day35-----MVC three-tier architecture
Why did you start preparing for the soft exam just after the PMP exam?
[BSidesCF 2019] Kookie
说说数据治理中常见的20个问题
重新审视分布式系统:永远不会有完美的一致性方案……
u-boot debugging and positioning means


![[cesium] element highlighting](/img/99/504ca9802db83eb33bc6d91b34fa84.png)




