How to use css variables in JSUse the :export keyword to export a js object in a less/scss file. $menuText:#bfcbd9; $menuActiveText:#409EFF; $subMenuActiveText:#f4f4f5; // $menuBg:#304156; $menuBg:#304156; $menuHover:#263445; $subMenuBg:#1f2d3d; $subMenuHover:#001528; $backWhite:#ffffff; $sideBarWidth: 210px; :export { menuText: $menuText; menuActiveText: $menuActiveText; subMenuActiveText: $subMenuActiveText; menuBg: $menuBg; menuHover: $menuHover; subMenuBg: $subMenuBg; subMenuHover: $subMenuHover; sideBarWidth: $sideBarWidth; backWhite: $backWhite; } Reference it in the required js file or module. import style from 'index.scss' console.log(style.menuText) vue file import style from 'index.scss' export default { computed:{ style(){ return style } } } Implementation principle Webpack: Combine with css-loader to enable CSS Modules in your project. CSS Modules: CSS Modules uses ICSS internally to solve the problems of style import and export. They correspond to the two newly added pseudo-classes: :import and :export. Appendix: export javascript keywordJavascript keywords (Reserved Words) refer to those words that have specific meanings in the Javascript language and become part of the Javascript syntax. Javascript keywords cannot be used as variable names or function names. Using Javascript keywords as variable names or function names will cause compilation errors during the Javascript loading process. Javascript Keywords List:
Javascript future keywords list:
SummarizeThis is the end of this article about how to use css variables in JS. For more relevant content about using css variables in JS, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of common knowledge points required for MySQL
>>: Detailed explanation of how to build a CDN server with Nginx (picture and text)
Recently, I want to build a hadoop test cluster i...
You can use the attribute in HTML5 <input="...
Database performance optimization generally adopt...
Content 1. Give readers a reason to stay. Make the...
1. Check the synchronization status of A and B da...
CentOS8 was released a few days ago. Although it ...
Table of contents Introduction and Demo API: Cont...
Table of contents Preface XA Protocol How to impl...
Introduction to Nginx dynamic and static separati...
Some command differences between versions: show i...
CJK is the abbreviation of CJK Unified Ideographs...
View the dependent libraries of so or executable ...
XHTML defines three document type declarations. T...
Table of contents MySQL Common Functions 1. Numer...
Long story short, today we will talk about using ...