React双向绑定input

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)} />

猜你喜欢

转载自blog.csdn.net/qq_42555578/article/details/107083566