首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Pug条件、分支条件

Pug条件、分支条件

作者头像
听着music睡
发布2020-02-26 17:15:34
1.9K0
发布2020-02-26 17:15:34
举报
文章被收录于专栏:Android干货Android干货
- var friends = 10
case friends
  when 0
    p 您没有朋友
  when 1
    p 您有一个朋友
  default
    p 您有 #{friends} 个朋友

等价于--->
<p>您有 10 个朋友</p>

另一种块展开的写法:

- var friends = 1
case friends
  when 0: p 您没有朋友
  when 1: p 您有一个朋友
  default: p 您有 #{friends} 个朋友
- var friends = 0
case friends
  when 0
  when 1
    p 您的朋友很少
  default
    p 您有 #{friends} 个朋友

等价于-->
<p>您的朋友很少</p>

friends =0 ,在 Pug 中则是,传递会在遇到非空的语法块前一直进行下去,所以满足了 0 1

若想只执行when 0

给分支加上-break

if 条件

- var user = { description: 'foo bar baz' }
- var authorised = false
#user
  if user.description
    h2.green 描述
    p.description= user.description
  else if authorised
    h2.blue 描述
    p.description.
      用户没有添加描述。
      不写点什么吗……
  else
    h2.red 描述
    p.description 用户没有描述


等价于--->
<div id="user">
  <h2 class="green">描述</h2>
  <p class="description">foo bar baz</p>
</div>

反义使用:

unless user.isAnonymous
  p 您已经以 #{user.name} 的身份登录。

等价-->
if !user.isAnonymous
  p 您已经以 #{user.name} 的身份登录。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-02-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档