标签:turn com src color img input 技术 inpu targe
class DataBinding extends React.Component { constructor() { super() this.state = { userName: ‘双向绑定‘ } } // --------------- e.target inputChange = e => { this.setState({ userName: e.target.value }) } getData = () => { alert(this.state.userName) } // ---------------- ref inputCha =() => { let val = this.refs.username.value this.setState({ userName: val }) } getUser = () => { alert(this.state.userName) } render() { return ( <div> <input value={this.state.userName} onChange={this.inputChange}></input> <button onClick={this.getData}>点击获取</button> <p>{this.state.userName}</p> <input ref="username" value={this.state.userName} onChange={this.inputCha}/> <button onClick={this.getUser}>点击获取</button> </div> ) } }
标签:turn com src color img input 技术 inpu targe
原文地址:https://www.cnblogs.com/yangisme/p/12465285.html