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"] ...
随机推荐
- 《团队名称》第八次团队作业:Alpha冲刺day1
项目 内容 这个作业属于哪个课程 2016计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8-软件测试与ALPHA冲刺 团队名称 快活帮 作业学习目标 (1)掌握 ...
- discuz x3.3后台admin.php防止直接恶意访问
功能说明:admin.php是discuz默认的后台地址,正常情况下可以直接访问,为了防止某些恶意访问的情况,可以修改以下内容进行安全性能提升. 适用版本:Discuz!x1-x3.3 具体实施方案: ...
- arrayAppend.php
<?php $t_full_projects = array(); $t_full_projects[] ='a'; $t_full_projects[] ='b'; $t_full_proje ...
- web万维网 -- 基础概念
Web(万维网World Wide Web的简称)是个包罗万象的万花筒,不同的人从不同的角度观察,对于Web究竟是什么会得出大不相同的观点. 百科:web(World Wide Web)即全球广域网, ...
- gettid和pthread_self区别
http://blog.csdn.net/rsyp2008/article/details/45150621 1 线程ID获取方法 Linux下获取线程有两种方法: 1)gettid或者类似getti ...
- winform窗体的常用属性
- Android Studio软件技术基础 —Android项目描述---1-类的概念-android studio 组件属性-+标志-Android Studio 连接真机不识别其他途径
学习android对我来说,就是兴趣,所以我以自己的兴趣写出的文章,希望各位多多支持!多多点赞,评论讨论加关注. 最近有点忙碌,对于我来说,学习Android开发,是对于我的考验,最近一位大佬发给我一 ...
- glew的安装
下载链接: https://sourceforge.net/project/downloading.php?group_id=67586&filename=glew-1.5.1-win32.z ...
- shell 输出文件各行的长度
test.sh #!/bin/bash string="hello,shell,split,test" array=(${string//,/ }) for var in ${ar ...
- JavaScript Date对象和函数 (一)
JavaScript_Date对象说明 Date中文为"日期"的意思,Date继承自Object对象,此对象提供操作,显示日期与时间的函数 Date对象构造函数 Date对象具有 ...