如下内容都是浏览器最终运行的代码,若是是react或者vue的必须是编译以后的文件
html中须要有一些内容css
<link rel="stylesheet/less" type="text/css" href="/color.less" /> <script> window.less = { async: false, env: "production" //production development }; </script> <script src="https://cdn.bootcss.com/less.js/2.7.3/less.min.js"></script>
这样在js中就能够直接修改变量了html
$('#color-switch a').click(function() { var value = $(this).text(); less.modifyVars({'@my-color': value}); less.refreshStyles();//好像无关紧要 });
上面那个color.less文件中必须有这个变量的定义和使用vue
@my-color:red; .mydiv{ color:@my-color; }
若是less文件中没有这个变量的定义或者没有这个变量的使用,js切换是没有效果的react