只需
setInterval进入componentDidMount函数即可。
像这样 :
componentDidMount() { setInterval(() => { this.setState({ curTime : new Date().toLocaleString() }) }, 1000) }这将更改状态并每1秒更新一次。

只需
setInterval进入componentDidMount函数即可。
像这样 :
componentDidMount() { setInterval(() => { this.setState({ curTime : new Date().toLocaleString() }) }, 1000) }这将更改状态并每1秒更新一次。