类属性

class 属性可以是一个字符串(与任何普通属性一样),但它也可以是一个类名数组,从 JavaScript 生成时很方便。

码:

- var classes = ['foo', 'bar', 'baz']
a(class=classes)
//- the class attribute may also be repeated to merge arrays
a.bing(class=classes class=['bing'])

结果:

<a class="foo bar baz"></a><a class="bing foo bar baz bing"></a>

它也可以是将类名映射到 true 或 false 值的对象,这对应用条件类很有用

码:

- var currentUrl = '/about'
a(class={active: currentUrl === '/'} href='/') Home
a(class={active: currentUrl === '/about'} href='/about'

结果:

<a href="/">Home</a><a href="/about" class="active">About</a>