使用less.js更改单个变量 [英] Change a single variable with less.js

查看:1887
本文介绍了使用less.js更改单个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用less.js修改一个较少的样式表用于演示。我想要做的是记住以前的更改,所以我只需要发送单次更改每次的效率。让我们说,我有以下:

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;

我的问题是,是否有一种方法或方法只是更改one参数,其他更改单独?

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

推荐答案

快速查看 modifyVars的源代码似乎确认你不能这样做。

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

看起来每次调用 modifyVars时都会重新编译源 .less / code>,并且只应用在最后的 modifyVars 调用中传递的那些更改。

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.

这篇关于使用less.js更改单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆