rea*_*rns 1 javascript state onchange setstate reactjs
努力获取滑块以更改 React 状态中“文本”的值。
一直报错:
“App.js:90 Uncaught TypeError: this.setState is not a function”尽管我尽了最大努力进行故障排除。
解决办法是什么?
class App extends Component {
constructor(props) {
super(props);
this.state = {list: [{x: "Before Pool", y:85000}, {x: "After Pool", y:82000}], text: 0, options: {bathrooms:'', bedrooms:'', sqft:''}};
}
componentDidMount() {
setTimeout(() => {
this.setState({list: [{x: "Before Pool", y:60000}, {x: "After Pool", y:30000}]});
console.log("testing", this.state.text);
}, 2000) ;
}
handleChange (event) {
console.log("from handle change", event);
this.setState({text : event });
}
render() {
return (
<div className="App">
<div>
<div style={wrapperStyle}>
<p># of Bathrooms</p>
<Slider min={0} max={20} defaultValue={3} onChange={this.handleChange} />
</div>
Run Code Online (Sandbox Code Playgroud)
你需要绑定handleChange方法
<Slider min={0} max={20} defaultValue={3} onChange={this.handleChange.bind(this)}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4208 次 |
| 最近记录: |