当前位置:网站首页>【微信小程序】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
边栏推荐
- 4T硬盘剩余很多提示“No space left on device“磁盘空间不足
- Why did you start preparing for the soft exam just after the PMP exam?
- u-boot in u-boot, dm-pre-reloc
- 浅析主流跨端技术方案
- What is ASEMI photovoltaic diode, the role of photovoltaic diode
- In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
- [informix] Resolving startup errors and solutions
- How to identify false evidence and evidence?
- bytebuffer put flip compact clear 方法演示
- Redis - 13. Development Specifications
猜你喜欢
![[MRCTF2020]Ezpop(详解)](/img/19/920877ca36d1eda8d118637388ab05.png)
[MRCTF2020]Ezpop(详解)

In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit

Analyses the mainstream across technology solutions

JeeSite New Report

服务器磁盘阵列
![[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]](/img/f3/0d92e22a424206241f4e1640f1bf6b.png)
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]

Machine Learning Overview

mutillidae download and installation

Dephi逆向工具Dede导出函数名MAP导入到IDA中

【cesium】加载并定位 3D Tileset
随机推荐
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
mutillidae download and installation
bytebuffer internal structure
[SWPU2019]Web1
七夕节赚徽章拉
Redis - 13、开发规范
Qixi Festival earn badges
[BSidesCF 2019] Kookie
ansible各个模块详解
开发属于自己的node包
bytebuffer use demo
Some conventional routines of program development (1)
人性的弱点
Machine Learning Overview
Day019 Method overriding and introduction of related classes
Flutter learning three-Flutter basic structure and principle
There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space
【informix】解决启动报错大全,以及解决办法
C语言-大白话理解原码,反码和补码