三元表达式实现三个条件的判断

status === 1 ? 
    <div class="article-card-tag article-tag-real">确认属实</div> :
status === 2 ?
    <div class="article-card-tag article-tag-fake">谣言</div> :
status === 3 ? 
    <div class="article-card-tag article-tag-uncertain">尚无定论</div> :
    <div class="article-card-tag article-tag-real">确认属实</div>

输出结果:

条件=1:确认属实

条件=2:谣言

条件=3:尚无定论

 

<p>{item === 'accessPoint' ? '接入点位' : (item === 'alarmCount' ? '报警次数' : (item === 'resolveAlarm' ? '解决隐患' : '巡检次数'))}</p>

 多条件判断赋值

let objs = {
   zsNames: {
       names: '张三'
   },
   wwNames: {
      names: '王五'
   }
   lsNames: {
      names: '李四'
   }
}
let names;
function getName(index) {
     names = objs[index].names;
}

 

posted @ 2020-07-07 11:48  Running°つ  阅读(10447)  评论(2编辑  收藏  举报