【问题标题】:Import file based on condition - scss根据条件导入文件 - scss
【发布时间】:2021-12-31 13:24:57
【问题描述】:

我有一个有 2 个主题的网站,我正在尝试根据当前设置为主体 ID 的主题设置我的配置。

我可以根据这种情况导入文件吗?像这样的:

#theme1 {
   @import "components/theme-one-styling";
}
#theme2 {
   @import "components/theme-two-styling";
}

希望这是有道理的

谢谢

【问题讨论】:

    标签: sass scss-mixins sass-variables


    【解决方案1】:

    我不知道该怎么做,但您的问题的另一个解决方案是,为主题设置 2 个单独的 mixin,将其放在同一个文件中,并将该 mixin 包含在您的组件 scss 中。像这样的:

    第 1 步:称为组件/主题的通用文件

    @mixin theme-1-mixin() {
     /// write your code for theme 1
    }
    
    @mixin theme-2-mixin() {
     /// write your code for theme 2
    }
    

    在您的组件 scss 文件中,执行以下操作:

    @import 'components/themes';
    
    #theme1 {
      @include theme-1-mixin();
    }
    
    #theme2 {
      @include theme-2-mixin();
    }
    
    

    不确定这是否会解决问题,但只是另一种解决方案。

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 2018-11-08
      • 2018-02-22
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 2020-05-13
      相关资源
      最近更新 更多