Solution in Less.js v1.0.31
To address this limitation, version 1.0.31 of Less.js introduced a method called less.refreshStyles(). This method enables the recompilation of
In JavaScript:
less.refreshStyles();","image":"http://www.luping.net/uploads/20241116/17317674096738ac716c563.jpg","datePublished":"2024-11-16T23:10:36+08:00","dateModified":"2024-11-16T23:10:36+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}
Loading Less.js Rules Dynamically
Incorporating Less.js into a website can enhance its styling capabilities. However, one limitation encountered is the requirement to load all LESS stylesheets before the Less.js script. This can pose a challenge when certain styles need to be loaded dynamically post initial page load.
Current Limitations
Presently, Less.js dictates that the order of loading external stylesheets and the script play a crucial role. Reversing the order, as shown below, fails to load the style.less file in both Firefox and Chrome:
Solution in Less.js v1.0.31
To address this limitation, version 1.0.31 of Less.js introduced a method called less.refreshStyles(). This method enables the recompilation of
Implementing Dynamic Loading
To implement dynamic loading of Less.js rules, follow these steps:
Example:
In JavaScript:
less.refreshStyles();
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3