玉:如果那么短版

时间:2017-07-11 17:32:38

标签: conditional pug

我有这个有效的代码

if (activePage === 'index')
    a.active(href="index.html") Index
else
    a(href="index.html") Index

我想用以下内容缩短它:

- var vclass = #{activePage==='popol' ? 'active' : ''};
a(class=#{vclass}) Index

或更好的像

a(class=#{activePage==='index' ? 'active' : ''}) Index

1 个答案:

答案 0 :(得分:2)

我认为这段代码应该有效并且更好

a(href='index.html' class=activePage === 'index' ? 'active' : '') Index