react 并没有vue v-model 这样的指令,今天要用onchange和setState实现
<div>
<input onChange={this.change.bind(this)} value={this.state.value} type="text" />
<p>值:{this.state.value}</p>
</div>
下面是函数然后因为setstate是异步的
async change(e) {
// console.log(e.target.value)
await this.setState({
value: e.target.value
})
await console.log(this.state.value)
}
这样就可以咯