Sass - 错误指令



说明

@error 指令将 SassScript 表达式值显示为致命错误。

示例

以下给出了与 css 文件类似且扩展名为 .scss 的样式表文件。

warn.scss

$colors: (
   blue: #c0392b,
   black: #2980b9,

);

@function style-variation($style) {
   @if map-has-key($colors, $style) {
      @return map-get($colors, $style);
   }

   @error "Invalid color: '#{$style}'.";
}

.container {
   style: style-variation(white);
}

你可以告诉 SASS 监视该文件,并在 SASS 文件更改时更新 CSS,方法是使用以下命令 −

sass --watch C:\ruby\lib\sass\warn.scss:warn.css

当你运行上述命令时,它会自动创建 error.css 文件。每当你更改 SCSS 文件时,error.css 文件将会自动更新。

输出

让我们执行以下步骤来了解如何使上述代码工作并报错 −

  • 将以上给定的代码保存在 error.scss 文件中。

  • 在命令提示符中运行以上提到的命令行。

Sass rules and directives
sass_rules_and_directives.htm
广告
© . All rights reserved.