iconfont
不止有单色、双色的图标,还有很多【多色】的图标,于是不能【去色】,只能手动替换primary
新建一个iconfont
,替换过主题色的,然后与旧的iconfont
配合切换使用
主要如下:
reqiure
之前必须【清除缓存】,否则无法生效,require
加载机制如上图所示
javascript
const onChangeYellow = (index) => {
if (appPrimary.value === "yellow") {
// 重新设置主题色
document
.getElementsByClassName("skin-variant--semi-dark")[0]
.style.setProperty("--v-primary-base", "#EDE20B");
document
.getElementsByClassName("v-main")[0]
.style.setProperty("--v-primary-base", "#323232");
vm.$vuetify.theme.themes.dark.primary = "#323232";
// document.getElementsByTagName('html')[0].className = appPrimary.value
document.documentElement.className = appPrimary.value;
// 清除缓存
delete require.cache[require.resolve("@/assets/yellow-iconfont/iconfont")];
delete require.cache[
require.resolve("@/assets/yellow-iconfont/iconfont.css")
];
// 引入新的iconfont文件
require("@/assets/yellow-iconfont/iconfont");
require("@/assets/yellow-iconfont/iconfont.css");
} else {
document
.getElementsByClassName("skin-variant--semi-dark")[0]
.style.removeProperty("--v-primary-base");
document
.getElementsByClassName("v-main")[0]
.style.removeProperty("--v-primary-base");
// document.getElementsByTagName('html')[0].className = ''
document.documentElement.className = "";
// document.getElementsByClassName('yellow-iconfont')[0].remove()
delete require.cache[require.resolve("@/assets/iconfont/iconfont")];
delete require.cache[require.resolve("@/assets/iconfont/iconfont.css")];
require("@/assets/iconfont/iconfont");
require("@/assets/iconfont/iconfont.css");
}
};