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模擬了按鈕點擊,具體邏輯自己加

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章