React Native学习之DeviceEventEmitter传值


 使用DeviceEventEmitter前需添加

import {
     AppRegistry,
     StyleSheet,
     Text,
     View,
     DeviceEventEmitter
 } form 'react-native';

 

 添加DeviceEventEmitter

componentDidMount() {
     this.subscription = DeviceEventEmitter.addListener('userNameDidChange',(userName) =>{
          alert('通知');
     })
},

 

 移除DeviceEventEmitter

componentWillUnmount() {
    // 移除
    this.subscription.remove();
},

 

 发送通知

DeviceEventEmitter.emit('userNameDidChange', '通知来了');

 

 OK, 完成! 赶紧试试吧! ~~


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM