【发布时间】:2021-10-07 02:18:48
【问题描述】:
我的前端有整个主题系统 它基于使用 mixin 更改 CSS 变量来更改颜色:
--sysPrimary: #03d5f7;
--sysSecondary: #05fcac;
--sysHover: #76D9F5;
--sysWarning: #ff4146;
--sysBackground: #23242c;
--sysDarkbackground: #202228;
--sysInputBg: #494b54;
--sysGrey: #bbbbbb;
--sysText: #ffffff;
--menuPrimary: #03d5f7;
--menuSecondary: #05fcac;
--menuHover: #76D9F5;
--menuText: #000000;
--menuTextHover: #000000;
--menuIcons: #000000;
--menuIconsHover: #000000;
因此,只需单击一个按钮,我就可以选择一个键,css 变量也会相应地改变
_systemStyles() {
return {
'--sysPrimary': this._colorTheme.primary,
'--sysSecondary': this._colorTheme.secondary,
'--sysHover': this._colorTheme.hover,
'--sysWarning': this._colorTheme.warning,
'--sysBackground': this._colorTheme.bg,
'--sysDarkBackground': this._colorTheme.darkBg,
'--sysText': this._colorTheme.text,
'--sysGrey': this._colorTheme.grey,
'--menuPrimary': this._colorTheme.menu_primary,
'--menuSecondary': this._colorTheme.menu_secondary,
'--menuHover': this._colorTheme.menu_hover,
'--menuText': this._colorTheme.menu_text,
'--menuTextHover': this._colorTheme.menu_text_hover,
'--menuIcons': this._colorTheme.menu_icons,
'--menuIconsHover': this._colorTheme.menu_icons_hover,
}
},
我所做的只是在我的 app.vue 文件中添加:style="_systemStyles",仅此而已……一切都是自动化的。
现在,当我使用在我的<body></body> 标记上呈现 HTML 元素的第三方库时出现问题。
由于我的应用程序嵌套在我的正文中,因此只有嵌套在我的应用程序中的元素会受到我的 CSS 变量更改的影响。
由于该库附加在主体级别...它仅获取变量的根定义。
我需要一种方法将我的 body 元素与我的 _systemStyles 对象进行样式绑定。
我尝试过的事情:
获取 body 元素并尝试用我的对象覆盖其样式 - 不计算
在我呈现应用程序的服务器上导入我的 scss 文件 - 没有真正发生超出范围
基本上就是这样......我想不出其他解决方案。
是的,当然我用谷歌搜索过,这是一个复杂的问题......
【问题讨论】:
标签: javascript html css vue.js vuejs2