问题描述
关于手写笔的一件大事是,它允许您定义可以使用的变量.自定义结果输出的配置.
One of the great things about Stylus is that it allows you to define variables which can be used to customize the configuration of the resulting output.
例如,
// my-html-object.styl
$my-html-object-color = red
$my-html-object
color $my-html-object-color
但是如何定义此变量,以便在加载"my-html-object.styl"之前可以覆盖该变量,以便可以进行以下操作?
But how would one define this variable so that it can be overridden before 'my-html-object.styl' is loaded such that the following is possible?
// main.styl
$my-html-object-color = blue
@import('my-html-object')
推荐答案
Stylus提供了两个相同的运算符来实现此?=
和:=
,如此处所述:
Stylus offers two identical operators to achieve this ?=
and :=
as documented here:
http://learnboost.github.io/stylus/docs/operators.html#conditional-assignment--
为完整起见,下面的示例显示了两种替代(但等效)语法:
For completeness here is an example showing the two alternative (but equivalent) syntaxes:
示例1:
// my-html-object.styl
$my-html-object-color ?= blue
$my-html-object
color $my-html-object-color
示例2:
// my-html-object.styl
$my-html-object-color := blue
$my-html-object
color $my-html-object-color
然后在两种情况下都可以根据需要调整值:
And then in both cases you can adjust the value as intended:
// main.styl
$my-html-object-color = blue
@import('my-html-object')
这篇关于假设触控笔样式表中的全局变量为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!