Change a single variable with less.js

南楼画角 提交于 2020-01-06 06:59:12

问题


I am trying to use less.js to make modifications to a less stylesheet for demonstration purposes. What I would like it to do is remember previous changes so I only have to send a single change each time for efficiency. Let's say I have the following:

@PrimaryColor: #FFF;
@SecondaryColor: #000;

If I change one parameter, it works fine.

less.modifyVars({ "@PrimaryColor": "#ff0000" });

The colors now look like this:

@PrimaryColor: #ff0000;
@SecondaryColor: #000;

Now if I call the method again:

less.modifyVars({ "@SecondaryColor": "#00ff00" });

The primary color switches back and the secondary color changes:

@PrimaryColor: #FFF;
@SecondaryColor: #00ff00;

My question is whether there is a way or a method that will just change the one parameter and leave the other changes alone?


回答1:


Quick look at the source code of modifyVars seems to confirm that you can't do it.

It looks like the source .less file is recompiled every time you call modifyVars and only those changes that you passed in the last modifyVars call are applied.



来源:https://stackoverflow.com/questions/19485685/change-a-single-variable-with-less-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!