Sass:声明只能在样式规则中使用

Oll*_*ams 7 sass

我收到 sass 错误:声明只能在样式规则中使用。

\n
   \xe2\x95\xb7\n32 \xe2\x94\x82     #{$property}: $value;\n   \xe2\x94\x82     ^^^^^^^^^^^^^^^^^^^^\n
Run Code Online (Sandbox Code Playgroud)\n

对于以下文件:

\n
@mixin theme($colour, $texture: null) {\n  $theme: map-get-strict($themes, $colour, "theme");\n\n  @if ($texture) {\n    @include getTexture($texture);\n  }\n\n  @each $property, $value in $theme {\n    #{$property}: $value;\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是使用 dart-sass。

\n

我认为这可能是导致问题的 Sass 测试文件,例如:

\n
@include it('outputs the light-blue theme') {\n    @include assert {\n      @include output {\n        @include theme(light-blue);\n      }\n\n      @include expect {\n        background-color: getColour(light-blue);\n        color: getColour(black);\n      }\n    }\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

小智 15

声明只能在样式规则内使用。

您只能样式规则中使用声明。这意味着如果你有一个包含声明的 mixin

例如:

@mixin foo() {
  color: #000;
}
Run Code Online (Sandbox Code Playgroud)

只能将其包含在样式规则中。

例如:

.bar {
  @include foo();
}
Run Code Online (Sandbox Code Playgroud)

这有助于确保编译后的 CSS 没有错误。


颜色:#000;

.bar {
  color: #000;
}
Run Code Online (Sandbox Code Playgroud)