需求
在修改样式时候,需要根据不同条件,使用不同的样式,使用动态类需要多重判断,是否考虑使用变量传入的方式呢
应该怎么做
tsx
import './App.css';
import './test.css'
function App() {
  const styles = {
    '--var': 'white',
  };
  return (
    <div className="App" style={styles}>
            <div className="custom-element">Hello, World!</div>
    </div>
  );
}
export default App;
 
css/less样式文件
.App {
  width: 100px;
  height: 100px;
  background: red;
  line-height: 100px;
}
.custom-element {
  color: var(--var);
}
 
展示效果

 










