创建一个不断 运行 的方法
Create a constantly running method
我想创建一个使用 momentjs 监视当前时间的方法,并将在特定时间执行 this.setState()
,在 react native 中。
我获取当前时间没问题,问题是,我需要某种方法,可以在后台持续 运行 并执行任务。
类似 angular 的 $scope.watch
适合熟悉 angular 的人。
您可以 运行 安装组件后的间隔时间:
componentDidMount() {
const interval = setInterval(() => {
//your logic here
this.setState({})
}, 300)
}
使用 setInterval
componentDidMount() {
let intervalId = setInterval(() => {
this.setTime({
time: //moment time
}
});
}
我想创建一个使用 momentjs 监视当前时间的方法,并将在特定时间执行 this.setState()
,在 react native 中。
我获取当前时间没问题,问题是,我需要某种方法,可以在后台持续 运行 并执行任务。
类似 angular 的 $scope.watch
适合熟悉 angular 的人。
您可以 运行 安装组件后的间隔时间:
componentDidMount() {
const interval = setInterval(() => {
//your logic here
this.setState({})
}, 300)
}
使用 setInterval
componentDidMount() {
let intervalId = setInterval(() => {
this.setTime({
time: //moment time
}
});
}