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)
Every website usually encounters many non-search ...
Table of contents 1. props/$emit Introduction Cod...
This article uses an example to describe how to s...
Simple function: Click the plug-in icon in the up...
Table of contents Preface Core - CancelToken Prac...
Table of contents 1. RegExp object 2. Grammar 2.1...
Recently, there is a need to automatically search...
Table of contents Problem Description Rendering T...
1. Target environment Windows 7 64-bit 2. Materia...
Simulation tables and data scripts Copy the follo...
1.What is margin? Margin is used to control the sp...
1. Download the tomcat compressed package from th...
Table of contents 1. Vertical (longitudinal) slic...
Using the clear property to clear floats is a comm...
1 CSS style without semicolon ";" 2 Tags...