1
在组件中,加载listview和所有内容。React-Native:在加载组件时在后台运行一个函数
是否可以在后台运行一个函数来每隔几分钟重新载入一次listview数据?
如果有, 当用户离开组件(转到另一个选项卡,iOS)时,该功能是否会停止?
在组件中,加载listview和所有内容。React-Native:在加载组件时在后台运行一个函数
是否可以在后台运行一个函数来每隔几分钟重新载入一次listview数据?
如果有, 当用户离开组件(转到另一个选项卡,iOS)时,该功能是否会停止?
您可以通过在componentDidMount中添加setInterval并在componentWillUnmount中将其清除来完成此操作。
let interval;
class HelloWorld extends Component {
componentDidMount() {
interval = setInterval(() => {
// do what you want here.
}, 10000);
}
componentWillUnmount() {
clearInterval(interval);
}
render() {
return (
<Text>Hello world!</Text>
);
}
}