【发布时间】:2017-02-25 01:47:48
【问题描述】:
我正在尝试进行状态更改,这将在 setTimeout 之后更改 className,但是,我不断收到“AboutHeader.jsx:21 Uncaught TypeError: this.setState is not a function”我尝试绑定(this)但它仍然无法正常工作。 从“反应”导入反应;
require('../../stylesheets/component/AboutHeader.scss');
导出默认类 AboutHeader 扩展 React.Component {
constructor() {
super()
this.timeDelay = this.timeDelay.bind(this);
this.state = {
class: "about-header-wrapper-hidden"
}
}
componentDidMount() {
console.log("mounted");
this.timeDelay();
}
时间延迟(){ setTimeout(function updateState(){this.setState({class: "about-header-wrapper"})}, 1000); console.log("timeDelay 工作"); }
render() {
return (
<section className={this.state.class}></section>
)
}
}
【问题讨论】:
标签: reactjs