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, 完成! 赶紧试试吧! ~~