弃用警告:在 calc() 之外使用 / 进行除法已弃用,并将在 Dart Sass 2.0.0 中删除

Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0

在这些函数中,我将 rem 编译为 px 并将 em 编译为 px:

$base: 16 !default;

@function scut-strip-unit($num) {
  @return $num / ($num * 0 + 1);
}

@function rem($pixels) {
  @return scut-strip-unit($pixels) / $base * 1rem;
}

@function em($pixels, $context: $base) {
  @return #{$pixels / $context}em;
}

但是 Sass v1.49,我们面临这个错误:

Error
Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.    

Recommendation: math.div(scut-strip-unit($pixels), $base) or calc(scut-strip-unit($pixels) / $base)    

More info and automated migrator: https://sass-lang.com/d/slash-div 
   
  ╷
8 │ @return scut-strip-unit($pixels) / $base * 1rem;

意思是您应该使用 sass:math 中的 math.div 进行除法,如下所示:

@use "sass:math";

@function rem($pixels) {
  @return math.div($pixels, 16) * 1rem;
}

要避免使用 sass:math,您可以只使用

calc(scut-strip-unit($pixels) / $base)