less.modifyVars改颜色主题

index.html增加

<link rel="stylesheet/less" type="text/css" href="theme.less" />

  

theme.less文件内容:
@primary-color: #000;
body {
  background-color: @primary-color;
}

  

想再哪个页面有:

先引入less

import less from 'less'; 

再使用

public componentDidMount() {
    setTimeout(() => {
      less.modifyVars({
        '@primary-color': 'red',
      });
    }, 5000);
  }

  

用setTimeout模拟了按钮点击,具体逻辑自己加

原文地址:https://www.cnblogs.com/juexin/p/15320787.html