//下载classnames
yarn add classnames
import React, { Component } from 'react'
import classNames from 'classnames'
import "./index.css"
export default class index extends Component {
state={
isflag:false
}
changeColor=()=>{
this.setState((state,props)=>{
return{
isflag:!state.isflag
}
})
}
render() {
const {isflag}=this.state
return (
<div>
<h1 className={classNames("foo",{"hace":isflag})}>我是一个哈哈哈</h1>
<button onClick={this.changeColor}>改变颜色</button>
</div>
)
}
}
.hace{
color: aqua;
}