如何使手写笔查看已在其他作用域中初始化的变量?

问题描述 投票:3回答:1

在SASS中:

.DocumentationArticle

  $DocumentationArticle-Heading__TopLevel--Selector: null

  &-Heading
    &__TopLevel
      $DocumentationArticle-Heading__TopLevel--Selector: &
    &__Section
      @debug($DocumentationArticle-Heading__TopLevel--Selector) // OK: ".DocumentationArticle-Heading__TopLevel"

在手写笔中,变量值已更改,此更改仅在已更改的范围内可见:

.DocumentationArticle

  DocumentationArticle-Heading__TopLevel--Selector = null

  &-Heading
    &__TopLevel
      DocumentationArticle-Heading__TopLevel--Selector = selector()
    &__Section
      warn(DocumentationArticle-Heading__TopLevel--Selector) // null!

如何使DocumentationArticle-Heading__TopLevel--Selector新值在&__Section范围内可见?

stylus
1个回答
1
投票

Stylus提供了两个相同的运算符来实现此?=和:=,如此处所记录:

http://learnboost.github.io/stylus/docs/operators.html#conditional-assignment--

为了完整起见,下面的示例显示了两种替代(但等效)语法:

示例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

然后在两种情况下,您都可以按预期调整值:

// main.styl

$my-html-object-color = blue

@import('my-html-object')

我在这里找到了这个答案Assume default value for global variable in Stylus stylesheet?

© www.soinside.com 2019 - 2024. All rights reserved.