当前位置:网站首页>【微信小程序】条件渲染 列表渲染 原来这样用?
【微信小程序】条件渲染 列表渲染 原来这样用?
2022-06-30 02:54:00 【热爱编程的小白白】
目录
WXML 模板语法 - 条件渲染
1. wx:if
<view wx:if="{
{condition}}">ture</view><view wx:if="{
{type==1}}">type==1</view>
<view wx:elif="{
{type==2}}">type==2</view>
<view wx:else>type==3</view>
js:
Page({
data: {
type:1
},
})因为type的值为1,所以:

例如:
WXML:
<view wx:if="{
{type==1}}">主色调</view>
<view wx:elif="{
{type==2}}">普通按钮</view>
<view wx:else>无</view>
<button type="primary" size="mini" wx:if="{
{type==1}}">主色调</button>
<button size="mini" wx:if="{
{type==2}}">普通按钮</button>JS和上面的一样
效果:
2. 结合 <block> 使用 wx:if
<block wx:if="{
{true}}">
<view>view1</view>
<view>view2</view>
<view>view3</view>
</block>

3. hidden
<view hidden="{
{false}}">hidden</view>
hidden 中 false 表示不隐藏组件
4. wx:if 与 hidden 的对比
WXML 模板语法 - 列表渲染
🥭1. wx:for
<view wx:for="{
{arry}}">
索引是:{
{index}},item项是:{
{item}}
</view>JS:
Page({
data: {
arry:['橘子','苹果','香蕉']
}
})

2. 手动指定索引和当前项的变量名

3. wx:key 的使用
<view wx:for="{
{userList}}" wx:key="id">
{
{item.name}}
</view>JS:
Page({
data: {
userList:[
{id:1,name:'热'},
{id:2,name:'爱'},
{id:3,name:'编'},
{id:4,name:'程'},
{id:5,name:'的'},
{id:6,name:'小'},
{id:7,name:'白'},
{id:8,name:'白'},
]
}
})效果:

边栏推荐
- Unity3d ugui force refresh of layout components
- Study diary: February 15, 2022
- 迅為恩智浦iTOP-IMX6開發平臺
- Five cheapest wildcard SSL certificate brands
- 并发请求下如何防重复提交
- oracle怎么设置密码复杂度及超时退出的功能
- O & M (21) make winpe startup USB flash disk
- 2022护网行动在即,关于护网的那些事儿
- Azure developer news flash list of events of developers in June
- FDA ESG regulation: digital certificate must be used to ensure communication security
猜你喜欢

Unity TimeLine 数据绑定

What files does a CA digital certificate contain? How to view SSL certificate information?

Raki's notes on reading paper: named entity recognition as dependency parsing

How to prevent phishing emails? S/mime mail certificate

Differences among digicert, SECTIONO and globalsign code signing certificates

Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla

JMeter obtains cookies across thread groups or JMeter thread groups share cookies

Intel hex, Motorola S-Record format detailed analysis

Unity3D UGUI强制刷新Layout(布局)组件

Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
随机推荐
Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
2.8 【 weight of complete binary tree 】
怎么利用Redis实现点赞功能
Distributed file storage system fastdfs hands on how to do it
Precautions for purchasing wildcard SSL certificate
公司电脑强制休眠的3种解决方案
The rigorous judgment of ID number is accurate to the last place in the team
Add a custom button to jvxetable
Interrupt operation: abortcontroller learning notes
如何在 JupyterLab 中把 ipykernel 切换到不同的 conda 虚拟环境?
JMeter obtains cookies across thread groups or JMeter thread groups share cookies
2022 underground coal mine electrical test and underground coal mine electrical simulation test
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
Three solutions to forced hibernation of corporate computers
怎么使用Vant实现数据分页和下拉加载
Federal learning: dividing non IID samples by Dirichlet distribution
What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
(graph theory) connected component (template) + strongly connected component (template)
oracle怎么设置密码复杂度及超时退出的功能
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla