React按键修改input框中的值

import React, { Component } from 'react';

class App extends Component {

  constructor(props){
  	super(props);
  	this.state = {
      inputVal:''
  	}
  }
  render () {
  	return (
  		<div>
        <input 
          type='text' 
          value={this.state.inputVal}
          onChange={this.inputChange.bind(this)}
        />
  		</div>
  	)
  }
  inputChange(e){
    let val = e.target.value;
    this.setState(()=>{
      return {
        inputVal:val
      }
    })

  }
}
export default App;

猜你喜欢

转载自blog.csdn.net/qq_43540219/article/details/107762247