我在我的 scss 文件中定义了不同的变量,我在一些 scss 文件中使用了这些变量。
_variables.scss
$light-theme: rgba(94,161,215,0.3);
$dark-theme: #5EA1D7;
$darker-theme: #57647A;
$very-dark-theme: #455061;
Run Code Online (Sandbox Code Playgroud)
如何定义 3 组主题?就像是:
default-theme {
$light-theme: rgba(94,161,215,0.3);
$dark-theme: #5EA1D7;
$darker-theme: #57647A;
$very-dark-theme: #455061;
}
dark-theme {
$light-theme: black;
$dark-theme: brown;
$darker-theme: black;
$very-dark-theme: black;
}
light-theme {
$light-theme: black;
$dark-theme: brown;
$darker-theme: black;
$very-dark-theme: black;
}
Run Code Online (Sandbox Code Playgroud)
我想根据选定的主题更改值。例如我有 3 个按钮,在它们上选择,将改变可变颜色。
应用程序组件.html
<button mat-raised-button (click)="onSetTheme('default-theme')">Default</button>
<button mat-raised-button (click)="onSetTheme('dark-theme')">Dark</button>
<button mat-raised-button (click)="onSetTheme('light-theme')">Light</button>
Run Code Online (Sandbox Code Playgroud)
app.component.ts
onSetTheme(theme) {
//TODO here I want to change the theme
}
Run Code Online (Sandbox Code Playgroud)
如何更改 onSetTheme() 函数内的主题。
谢谢!