当前位置: 代码迷 >> 综合 >> vue 使用 css/less 动态更换主题色
  详细解决方案

vue 使用 css/less 动态更换主题色

热度:43   发布时间:2023-10-10 19:08:27.0

.css

.drak-theme {--color-primary: #000000;
}.light-theme {--color-primary: pink;
}

在使用的地方动态切换的class(light-theme、drak-theme),与css定义的class一致

document.getElementById("app").className = "light-theme";
document.getElementById("app").className = "drak-theme";

一、全局引入css文件,在style中使用

<style lang="less">
.button {background-color: var(--color-primary);
}
</style>

二、在less中引入css文件,全局引入less

@import 'common.css';
@color-primary: var(--color-primary);

在style中使用

<style lang="less">
.button {background-color: @color-primary;
}
</style>

 

  相关解决方案