从Sass mixin更改全局变量

时间:2015-09-24 16:18:21

标签: scope sass variable-declaration

或者@content指令传递时,为什么全局变量在mixin范围内不会改变?

我将$ color变量定义为全局变量,并且其值已在mixin中设置。当我调用这个mixin时,我希望使用$ color作为mixin值,但是,通过@content指令传递变量,我总是得到全局值:

$color: #000 !default;

@mixin generate-fruits() {
    @each $fruit, $fruit-color in $fruits {
        $color: $fruit-color;
        .#{$fruit}{
            @content;

            //  Awaited result
            // background: $color;
        }
    }
}

@include generate-fruits(){
  background: $color;
};
  

结果:   背景变黑;

     

预期:   背景获得$ fruit-color

在Mixin操作之前似乎已经解析了@content。 如何强制@content保持* mixin范围

请找出问题on codePen的简化版本。

0 个答案:

没有答案
相关问题