import React from 'react';
import ReactDom from 'react-dom';
class HelloMessage extends React.Component {
constructor () {
super();
this.state = {
msg: 'hello'
};
this.handleChange = this.handleChange.bind(this);
}
handleChange (e) {
this.setState ({
msg: e.target.value
})
}
render () {
return (
<div>
<input type="text" value={this.state.msg} onChange={this.handleChange}/>
<h4>{this.state.msg}</h4>
</div>
)
}
}
ReactDom.render(
<div>
<HelloMessage />
</div>,
document.getElementById('root')
)
React—input框输入内容实时更新
最新推荐文章于 2023-04-17 11:06:29 发布