SCSS:如何使用变量来写样式类?

SCSS: How to use variables to write style classes ?

我想知道是否有某种方法可以使用影响 SCSS 样式的变量。

我正在寻找类似的东西:

var x = 1
.class1 { 
   if (x==1) {
       background-color: red;
   } else { 
       background-color: blue;
   }
}
.class2 { 
   if (x==1) {
       background-color: blue;
   } else { 
       background-color: red;
   }
}

您可以使用@if 和@else

$x:1;

.class1 { 
   @if $x == 1 {
       background-color: red;
   } @else { 
       background-color: blue;
   }
}
.class2 { 
    @if $x == 1 {
       background-color: blue;
   } @else { 
       background-color: red;
   }
}