React双向绑定input

    技术2022-07-15  67

    class Demo extends React.Component { constructor (props) { super(props); this.state = { input_val: '' }; } inputValChange = e => { this.setState({ input_val: e.target.value }); } render () { return ( <input value={this.state.input_val} onChange={this.inputValChange} /> ); } }

    传递多个参数

    inputValChange (e, params) { this.setState({ input_val: e.target.value, params }); } <input value={this.state.input_val} onChange={e => this.inputValChange(e, params)} />
    Processed: 0.010, SQL: 9