【发布时间】:2021-09-06 12:49:32
【问题描述】:
SCSS 对我来说相当陌生...我在 mixins SCSS 文件中创建一个函数,在运行 gatsby develop 时,我收到了一个未定义变量的 SassError,尽管“变量”是一个参数:
关于如何解决这个问题的任何建议?这是_mixins.scss中使用的代码开头的结构:
@use './units';
// Add transitions to attributes
@mixin transition($attrs, $speed: normal) {
$res: "";
// Multiple attributes
@if type-of($attrs) == list {
@each $attr in $attrs {
$res: #{$res}, _makeTransition($attr, $speed);
}
}
// One/no attribute
@else {
$res: _makeTransition($attr, $speed);
}
transition: $res;
}
@function _makeTransition($attr, $speed) {
$res: all map-get(units.$speed, $speed) cubic-bezier(0.4, 0, 0.2, 1);
// Attribute has default props
@if type-of($attr) == string {
$res: $attr map-get(units.$speed, $speed) cubic-bezier(0.4, 0, 0.2, 1);
}
// Attribute has custom props
@else if type-of($attr) == map {
$speed: if(map-has-key($attr, speed), map-get($attr, speed), $speed);
$res: map-get($attr, name)
map-get(units.$speed, $speed)
cubic-bezier(0.4, 0, 0.2, 1);
}
@return $res;
}
【问题讨论】: