letcolorArr=["red","yellow","blue","orange","pink","green","gray"];classHelloWorldextendsReact.Component{constructor(props){super(props);this.state={bgColor:"黄色"};this.toggleColor=this.toggleColor.bind(这个);this.changeColor=this.changeColor.bind(这个);}toggleColor(){if(this.state.bgColor=="yellow"){this.setState({bgColor:"red"});}else{this.setState({bgColor:"yellow"});}}componentDidMount(){让colorPos=0;setInterval(()=>{this.setState({bgColor:colorArr[colorPos]});if(colorArr.length-1>colorPos){颜色位置++;}else{colorPos=0;}},1000)}changeColor(event){this.setState({bgColor:event.target.value})}render(){console.log(this.props.name);//jsxletobjStyle={background:this.state.bgColor,fontSize:26};return(我叫嘉伟