努力获得一个滑块来更改 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>