React Native中定时器的使用
2016-12-28 23:44
579 查看
React Native中定时器的使用
React Native中定时器的使用分为ES5和ES6两种,前者使用较为麻烦ES5中使用方式
引入计时器类库var TimerMixin = require('react-timer-mixin');
注册计时器
mixins: [TimerMixin],
添加定时器
this.timer = this.setInterval(function() { }, 3000)
注意定时器开启就得有清除,一般在componentWillUnMount调用,图形卸载时清楚定时器也好理解
componentWillUnMount() { this.setInterval && clearInterval(this.setInterval) }
ES6中使用方式
很简单this.timer = setTimeout(function() { alert('3秒后弹出') }, 3000);
同样定时器开启就得有清除
this.timer && clearTimeout(this.timer)
相关文章推荐
- ReactNative-结合定时器使用ActivityIndicator
- An iOS Developer on React Native一个资深iOS开发者对于React Native具体使用体验
- react-native使用flux
- 【React Native开发】React Native控件之ToolbarAndroid工具栏控件讲解以及使用(15)
- 使用react-native做一个简单的应用-05 navigator的使用
- 【React Native开发】React Native控件之Switch开关与Picker选择器组件讲解以及使用(16)
- react-native使用react-art制作SVG动画
- 使用react-native做一个简单的应用-02项目搭建与运行
- 使用react-native做一个简单的应用-01项目介绍
- Android React Native使用原生模块
- Android React Native的使用细节问题
- React Native + Nodejs 使用RSA加密登录
- React Native Android 使用友盟SDK功能
- react-native之module的使用
- 学习React-Native(一):学习React,使用模块加载器webpack
- react native viewpager 使用问题
- 使用Jest对React-Native做单元测试
- 使用react-native做一个简单的应用-04界面主框架
- 【React Native开发】React Native控件之WebView组件详解以及实例使用(22)