react项目中js动态修改less文件中的变量实现修改样式
1.配置less
详细配置教程: https://blog.youkuaiyun.com/qq_42638586/article/details/117816588?utm_source=app&app_version=4.10.0&code=app_1562916241&uLinkId=usr1mkqgl919blen
2.创建less文件,并引入
在public目录下创建.less文件,其中可定义变量,如下图
在index.html中使用link标签引入less文件
<link rel='stylesheet/less' type="text/css" href="style.less"/>
(less文件不需要在js文件中引入,好像引入会不生效)
3.在js中修改变量
less.modifyVars({
'@dashboardLayoutBackground': 'pink'
}).then(res=>{
})