💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` hobbis.push(this.refs.hobby) ``` ``` hobbis.push(this.refs.hobby.value) ``` ``` addHobbyCallback(){ const hobbis = this.state.hobbis hobbis.push(this.refs.hobby.value) this.setState({ hobbis }) } render(){ return ( <div className="profile-component"> <h1>我的名字{this.props.name}</h1> <h2>我今年{this.props.age}</h2> <button onClick={this.likedCallback}>给我点赞</button> <h2>总点赞数:{this.state.liked}</h2> <h2>我的爱好</h2> <ul> {this.state.hobbis.map((hobby,i)=> <Hobby key={i} hobby={hobby} /> )} </ul> <input type="text" ref="hobby" /> <button onClick={this.addHobbyCallback}>添加爱好</button> </div> ) } ``` ``` addHobbyCallback(){ const hobbis = this.state.hobbis if(this.refs.hobby.value){ hobbis.push(this.refs.hobby.value) } this.setState({ hobbis },()=>{ this.refs.hobby.value = '' }) } ```