Scss换肤
项目中虽然没有一键换肤的要求,但是产品要求后期能换主题。在开发组件中涉及到主题的地方,要提取一些公用的变量,不要直接写死样式值。但是如果只是定义一些变量的话,只是完成控制颜色等值的提取。后期切换的话需要把所有变量再写一遍并注释之前的。不是很优雅。 一、Scss部分 定义变量以及映射表 // 默认主题 $default-theme : ( base-color: #ddd, border-color: #000 ); //红色主题 $red-theme : ( base-color: red, border-color: red ); //定义映射集合 $themes: ( default-theme: $default-theme, red-theme: $red-theme ); 定义方法,循环遍历映射集合,生成对应样式表 @mixin base-background(){ @each $themename , $theme in $themes { [data-theme = '#{$themename}'] & { background: map-get($map: $theme, $key: base-color ) } } } 在组件中,引入公共文件,在要用到的地方使用定义好的mixin @import 'theme.scss' .block { width: