今天在写 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 判断语句的更多相关文章

  1. SQLite的时候判断语句是否纯在:出现RuntimeException

    写SQLite的时候判断语句是否纯在: public boolean exist(long id) { String filter = FRIEND_KEY_ID + "=" + ...

  2. 第二周:If判断语句程序当中的作用简介

    1.If语句的作用: 在我们编写程序时经常会遇到内容判断的问题,比如判断内容的真假或者值的大小分别输出内容的问题 这时就会用到我们的If判断语句了,顾名思义,if在英文单词中意思为如果,在Java中他 ...

  3. 关于JavaScript的判断语句(1)

    if语句: if( 判断条件 ){ 判断结果为true执行语句: } if...else语句: if(判断条件){ 判断结果为true时执行的语句: }else{ 判断结果为false时执行语句: } ...

  4. SQL判断语句用法和多表查询

    1.格式化时间sql语句 本例中本人随便做了两张表,和实际不是很相符,只是想说明sql语句的写法. 例1表格式如下: 需求:查询出本表,但需要使time字段的时间格式为yyyy-MM-dd,比如:20 ...

  5. VB的判断语句和循环语句

      判断语句 •If语句 if语句共有4种写法: 第一种语法: If 条件判断语句 then 程序代码 第二种语法:If 条件判断语句 then 程序代码 else 程式代码 第三种语法: If 条件 ...

  6. 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). 分析: 首先想到的是写递归函数,但是遇 ...

  7. 求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) 分析:这题本来很 ...

  8. aspcms中if判断语句的运用

    1.<h3 {if:"[list:isrecommend]"="1"} style="color:red;"{end if}>& ...

  9. if条件判断语句的不同

    let number = ["a":1, "b":2, "c":3]; if let num = number["d"] ...

随机推荐

  1. M × N Puzzle

    http://poj.org/problem?id=2893 来自逆序对的强大力量 #include<iostream> #include<stdio.h> #include& ...

  2. Spring Cloud 组件 —— gateway

    Spring Cloud 网关主要有三大模块:route.predicates.filters 其中 filter 最为关键,是功能增强的核心组件. 列举出一些功能组件: 5.6 CircuitBre ...

  3. Opencv 初探 常用API

    一.介绍 OpenCV是计算机视觉领域应用最广泛的开源工具包,基于C/C++,支持Linux/Windows/MacOS/Android/iOS,并提供了Python,Matlab和Java等语言的接 ...

  4. 无故出现 mysql dead but subsys locked的有关问题

    无故出现 mysql dead but subsys locked的问题问题描述:1.mysql安装完成后,使用service mysqld restart总是出现stop mysqld servic ...

  5. linux下如何完全删除用户

    1.首先进入系统创建一个用户 [root@localhost /]# useradd haha   #创建用户  haha是用户名 [root@localhost /]# passwd haha    ...

  6. Feign发送Get请求时,采用POJO对象传递参数的最终解决方案 Request method 'POST' not supported (附带其余好几个坑)

    yml: feign: httpclient: enabled: true properties: #feign feign.httpclient.enabled=true <!-- https ...

  7. HDU 6091 - Rikka with Match

    思路 树形dp,设计状态如下: 设 $dp_u_i_0$表示 以点 u 为根的子树 最大匹配数模 m 为 i 时,且 u 点没有匹配的方案数 DP[u][i][1] 表示 以点 u 为根的子树 最大匹 ...

  8. 面向开发人员的Windows错误报告(WER)

    Windows错误报告是更新的Windows XP上Dr.Watson的替代品.它监视故障并收集可以发送到要分析的服务器(如果用户允许)的有用信息.这项功能帮助微软修复了很多错误——由于收到的报告,微 ...

  9. linux高性能服务器编程 (七) --Linux服务器程序规范

    第七章 LInux 服务器程序规范 1)linux服务器程序一般以后台进程形式运行.后台进程又称为守护进程,是没有控制终端的,所以不会受到外界的干扰.守护进程的父进程通常是init进程(PID为1的进 ...

  10. 基于vue和echarts的数据可视化实现

    基于vue和echarts的数据可视化: https://github.com/MengFangui/awesome-vue.git