React 使用 if else 判断语句
今天在写 React 时,在 render 的return中既然不能使用if判断语句,所以就整理一些在react中使用if 的方式,可根据自己的实际情况选择:
方式一:
class LLL extends React.Component {
constructor(props){
super(props);
this.judge = false
}
render(){
let Message
if (this.judge) {
Message = (
<span>
<h5>It`s my life!</h5>
</span>
)
} else {
Message = (
<h5>I think that's more than just like it!</h5>
)
}
return(
<div>
<h4>Wellcom LLL</h4>
{Message}
</div>
);
}
}
方式二:
class LLL extends React.Component {
constructor(props){
super(props);
this.judge = false
}
Message(){
if (this.judge) {
return (
<span>
<h5>It`s my life!</h5>
</span>
)
} else {
return (
<h5>I think that's more than just like it!</h5>
)
}
}
render(){
return(
//1
<div>
<h4>Wellcom LLL</h4>
{this.Message()}
</div>
);
}
}
方式三:三元运算符
class LLL extends React.Component {
constructor(props){
super(props);
this.judge = false
}
render(){
return(
//1
<div>
<h4>Wellcom LLL</h4>
{this.judge ? "It`s my life!" : "I think that's more than just like it!"}
</div>
);
}
}
方式四:
class LLL extends React.Component {
constructor(props){
super(props);
this.judge = false
}
render(){
return(
//1
<div>
<h4>Wellcom LLL</h4>
{
this.judge
?
<span>
<h5>It`s my life!</h5>
</span>
:
<h5>I think that's more than just like it!</h5>
}
</div>
);
}
}
React 使用 if else 判断语句的更多相关文章
- SQLite的时候判断语句是否纯在:出现RuntimeException
写SQLite的时候判断语句是否纯在: public boolean exist(long id) { String filter = FRIEND_KEY_ID + "=" + ...
- 第二周:If判断语句程序当中的作用简介
1.If语句的作用: 在我们编写程序时经常会遇到内容判断的问题,比如判断内容的真假或者值的大小分别输出内容的问题 这时就会用到我们的If判断语句了,顾名思义,if在英文单词中意思为如果,在Java中他 ...
- 关于JavaScript的判断语句(1)
if语句: if( 判断条件 ){ 判断结果为true执行语句: } if...else语句: if(判断条件){ 判断结果为true时执行的语句: }else{ 判断结果为false时执行语句: } ...
- SQL判断语句用法和多表查询
1.格式化时间sql语句 本例中本人随便做了两张表,和实际不是很相符,只是想说明sql语句的写法. 例1表格式如下: 需求:查询出本表,但需要使time字段的时间格式为yyyy-MM-dd,比如:20 ...
- VB的判断语句和循环语句
判断语句 •If语句 if语句共有4种写法: 第一种语法: If 条件判断语句 then 程序代码 第二种语法:If 条件判断语句 then 程序代码 else 程式代码 第三种语法: If 条件 ...
- Interview----求 1+2+...+n, 不能用乘除法、for、while if、else、switch、case 等关键字以及条件判断语句 (A?B:C)
题目描述: 求 1+2+...+n, 要求不能使用乘除法.for.while.if.else.switch.case 等关键字以及条件判断语句 (A?B:C). 分析: 首先想到的是写递归函数,但是遇 ...
- 求1+2+…+n,要求不能使用乘除法、for、while、if、else、s witch、case 等关键字以及条件判断语句(A?B:C)和不用循环/goto/递归输出1~100的10种写法
来源:据说是某一年某个公司的面试题 题目:求1+2+…+n, 要求不能使用乘除法.for.while.if.else.s witch.case 等关键字以及条件判断语句(A?B:C) 分析:这题本来很 ...
- aspcms中if判断语句的运用
1.<h3 {if:"[list:isrecommend]"="1"} style="color:red;"{end if}>& ...
- if条件判断语句的不同
let number = ["a":1, "b":2, "c":3]; if let num = number["d"] ...
随机推荐
- Linux-导入已安装的Linux系统
之前在安装过一个Linux系统,由于重装电脑需要将之前安装的系统重新移动到VMWare中,让Linux系统能够重新运行起来,这样也省去了每次重新安装系统的麻烦. 废话不多说,咱们直接看是如何做? 1) ...
- CodeForces - 1207G :Indie Album(AC自动机 fail树上DFS)
题意:有N个串,给出的形式是拼接给出,对于第i行: (1,c)表示字符串i是单个字母c: (2,p,c)表示字符串i=在字符串p后面接上一个字母c. 然后给出M个提问,形式是(i,string).问 ...
- 使用cookie登录网盘账号
①使用Chrome浏览器登录百度网盘网页版 https://pan.baidu.com/ ②查看当前使用的cookie ③获取BDUSS 注意是全选复制,不要直接复制,会不全的. ④获取STOKEN ...
- F Energy stones
题意是,有$n$个石头,每个石头有初始能量$E_i$,每秒能量增长$L_i$,以及能量上限$C_i$,有$m$个收能量的时间点,每次把区间$\left[S_i, T_i\right]$石头的能量都给收 ...
- OpenCV 学习笔记(2) 使用鼠标绘制矩形并截取和保存矩形区域图像
http://www.cnblogs.com/lidabo/p/3437587.html 0 效果展示 1工程源码 #include <opencv2/core/core.hpp> # ...
- 20101010 exam
目录 2018 10.10 exam 解题报告 T1:LOJ #10078 新年好 题目描述(原题来自:CQOI 2005): 输入格式: 输出格式: 样例输入: 样例输出: 数据范围与提示: 思路: ...
- poj2398 Toy Storage 计算几何,叉积,二分
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...
- virsh使用总结
做下面操作前先安装这些工具: yum install virt-install libvirt-admin libvirt-client libvirt-daemon libvirt主要的配 ...
- 关于window.getSelection
window.getSelection(),返回一个Selection对象,表示用户选择的文本范围或光标的当前位置. selection对象先来看下面两个selection结果:selection对象 ...
- 调用Fluent进行多工况计算总结
算例来源:https://confluence.cornell.edu/display/SIMULATION/FLUENT+-+Turbulent+Pipe+Flow 有时候我们对同一模型进行多工况计 ...