转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-15/

小程序里面也是有条件判断的,我相信大家在开发java if和jstl c:if c:when。有人说在程序员眼里只有if else,可见重要性。一起了解下微信小程序额的条件判断吧。源码:https://github.com/limingios/wxProgram.git 中的No.8

小程序的条件判断

  1. 官方的阐述
    >https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/conditional.html

  1. 演示条件判断
    >因为 wx:if 之中的模板也可能包含数据绑定,所以当 wx:if 的条件值切换时,框架有一个局部渲染的过程,因为它会确保条件块在切换时销毁或重新渲染。同时 wx:if 也是惰性的,如果在初始渲染条件为 false,框架什么也不做,在条件第一次变成真的时候才开始局部渲染。相比之下,hidden 就简单的多,组件始终会被渲染,只是简单的控制显示与隐藏。一般来说,wx:if 有更高的切换消耗而 hidden 有更高的初始渲染消耗。因此,如果需要频繁切换的情景下,用 hidden 更好,如果在运行时条件不大可能改变则 wx:if 较好。

ifElse.wxml

<!ifElse.wxml-->
<view class="container">
<view wx:if="{{age<18}}">未成年</view>
<view wx:elif="{{age>=18 &&age<=30}}">已成年</view>
<view wx:elif="{{age>30 &&age<=50}}">壮年,一起关注公众号:编程坑太多给我来点赞</view>
<view wx:else>已经老了</view> <block wx:if="{{false}}">
<view>这是一个块级元素</view>
<view>本节是if判断学习</view>
</block> <view hidden='{{true}}'>
<view>这是一个hidden元素</view>
<view>hidden判断学习</view>
</view>
</view>

ifElse.js

//ifElse.js
//获取应用实例
const app = getApp() Page({
data: {
age: 34
}
})

hidden true很像咱们css里面的display:none 元素是有的,只是屏幕不显示
wx:if 就类似咱们开发的java的jstl标签里面的if,直接元素就没有

PS:条件渲染也是很重要的,业务逻辑判断全靠它了。

「小程序JAVA实战」小程序视图之条件判断(15)的更多相关文章

  1. 「小程序JAVA实战」小程序的flex布局(22)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...

  2. 「小程序JAVA实战」小程序的留言和评价功能(70)

    转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...

  3. 「小程序JAVA实战」小程序的举报功能开发(68)

    转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...

  4. 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...

  5. 「小程序JAVA实战」小程序的关注功能(65)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...

  6. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  7. 「小程序JAVA实战」小程序的springboot后台拦截器(61)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...

  8. 「小程序JAVA实战」小程序首页视频(49)

    转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...

  9. 「小程序JAVA实战」小程序视频封面处理(48)

    转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...

随机推荐

  1. 【剑指offer12】矩阵中的路径(回朔法),C++实现

    1.题目 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵中 ...

  2. SpringDataJpa增删改查

    资料来源网址:http://www.cnblogs.com/hawell/p/SpringDataJpa.html Repository(几个常用的例子) @Repository public int ...

  3. POJ1741 Tree + BZOJ1468 Tree 【点分治】

    POJ1741 Tree + BZOJ1468 Tree Description Give a tree with n vertices,each edge has a length(positive ...

  4. MQ 发布/订阅者模式

    package com.chauvet.utils.mq.topic; import javax.jms.DeliveryMode; import javax.jms.JMSException; im ...

  5. 1153 Decode Registration Card of PAT (25 分)

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  6. My Test about Mat

    一.创建Mat >Mat a = cv::Mat(2,2,CV_32S,1); output:  [1,1; 1,1] >Mat a = cv::Mat(2,2,CV_32SC3,1); ...

  7. JLOI2019游记

    JLOI2019游记 DAY -??? 听说是12省联考,好刺激. DAY 1 看题 t1是个lydsy题我还写过博客,t2不会,t3一脸神仙. 这个t3数据好大啊,看到好几个人都用gedit打开大样 ...

  8. LeetCode 760. Find Anagram Mappings

    原题链接在这里:https://leetcode.com/problems/find-anagram-mappings/description/ 题目: Given two lists Aand B, ...

  9. vue的路由初识01

    今天就做了一个vue-router的实例,(路由跳转,参数的传递[一个参数,多个参数])<!DOCTYPE html> <html> <head> <meta ...

  10. Memory stream is not expandable

    发现项目有一个地方在做图片缩放剪切的一个操作中.碰到有一些特殊的图片会报 Memory stream is not expandable 的错误 跟踪的时候发现是 由方法 originalStream ...