在Jade/Pug中创建动态类 [英] Creating Dynamic Classes in Jade/Pug

查看:138
本文介绍了在Jade/Pug中创建动态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向Jade模板添加动态类.像这样:

I'm trying to add a dynamic class to a jade template. Like so:

- var obj = {a: 1, b: 2, c: 3};
- var len = Object.keys(obj).length;

.abc-#{len}

但是编译器对此采取了例外措施:

But the compiler is taking exception to this:

  > 4| .abc-#{len}
------------^

Unexpected token `interpolation` expected `text`, `interpolated-code`, `code`, `:`, `slash`, `newline` or `eos`

我已经尽力想了一切.正在 https://pugjs.org/language/interpolation.html 进行搜索.真的可以用一只手.

I've tried everything I could think of. Been scouring https://pugjs.org/language/interpolation.html. Could really use a hand.

谢谢.

推荐答案

您可以执行以下操作:

div(class="abc-"+len)

属性会自动中断,有关属性

attributes are interrupted automatically, more about attributes

这篇关于在Jade/Pug中创建动态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆