简体   繁体   English

在嵌套的mixin中使用SASS @each变量

[英]Use SASS @each variable inside nested mixin

I want to use Sass's built-in @each method to shorten this code: 我想使用Sass的内置@each方法来缩短此代码:

.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. 基本上,我需要能够在mixinSVG mixin的@each循环中使用变量名。 I am trying this but it is failing when it hits the @each variable inside the 'svg' property: 我正在尝试这样做,但是当它碰到'svg'属性内的@each变量时,它会失败:

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

You are messing with the named parameters. 您搞砸了命名参数。

It should look like this : 它应该看起来像这样:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM