首页 > 解决方案 > Use SASS @each variable inside nested mixin

问题描述

I want to use Sass's built-in @each method to shorten this code:

.svg-circle-full {
    @include mixinSVG((
        'svg': $svgvar-icn-circle-full,
        'isWide': false
    )...);
}

.svg-circle-empty {
    @include mixinSVG((
        'svg': $svgvar-icn-circle-empty,
        'isWide': false
    )...);
}

.svg-circle-half {
    @include mixinSVG((
        'svg': $svgvar-icn-circle-half,
        'isWide': false
    )...);
}

Basically I need to be able to use the variable name from my @each loop inside of the mixinSVG mixin. I am trying this but it is failing when it hits the @each variable inside the 'svg' property:

@each $state in full, empty, half {
    .svg-circle-#{$state} {
        @include mixinSVG((
        'svg': $svgvar-icn-circle-#{$state},
        'isWide': false
        )...);
    }
}

标签: cssloopssasseachscss-mixins

解决方案


您正在弄乱命名参数。

它应该是这样的:

@each $state in triangle, square, circle {
    .svg-circle-#{$state} {
        @include mixinSVG(
        $svg: svgvar-icn-circle-#{$state},
        $isWide: false
        );
    }
}

来源:http ://blog.ricardofilipe.com/post/object-arguments-in-sass


推荐阅读