import React, { Component } from 'react'
class App extends Component {
constructor(props) {
super(props)
//this.state = {} 定义数据
this.state = {
inputValue: ""
}
}
render() {
return (
<div>
{/* react里使用表达式,需要用大括号 */}
{/* react里绑定事件用驼峰命名,如,onChange */}
{/* react里需要改变this的指向,用bind(this) 把this指向到这个标签里 */}
<input type="text" value={this.state.inputValue} onChange={this.change.bind(this)} />
</div>
)
}
change(e) {
console.log(e.target.value);
//设置数据的值,用this.setState({})
this.setState({
inputValue: e.target.value
})
}
}
export default App;