How to assign to a global variable in Sass?

前端 未结 2 823
梦毁少年i
梦毁少年i 2020-11-27 08:08

I run this Sass code:

$a: 1;
@if 2 + 2 == 4 {
    $a: 2;
}
@debug $a;

I expect to see 2. The output, however, is:

Line 5 D         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 08:39

    By trial-and-error, I found a solution: I have to add !global in the assignment.

    $a: 1;
    @if 2 + 2 == 4 {
        $a: 2 !global;
    }
    @debug $a;
    

提交回复
热议问题