Skip to content
On this page

@block

在 Stylus 中,您可以将任意代码块赋值给变量,然后调用、作为参数传递或以其他方式复用。

定义代码块时,可以通过增加缩进后接赋值符号:

stylus
foo =
  width: 20px
  height: 20px
foo =
  width: 20px
  height: 20px

或使用带有 @block 关键字的大括号语法:

stylus
foo = @block {
  width: 20px
  height: 20px
}
foo = @block {
  width: 20px
  height: 20px
}

如果您想在任何地方渲染这个块,可以在插值中调用这个变量,例如:

stylus
.icon
  {foo}
.icon
  {foo}

将渲染为:

css
.icon {
  width: 20px;
  height: 20px;
}
.icon {
  width: 20px;
  height: 20px;
}

顺便说一下,这与您可以使用传递给块混合器的块的方式相同。

目前,您只能像传递其他变量一样传递变量并在插值中渲染它。未来我们将提供更多处理方式。

Released under the MIT License.