react 返回并刷新页面 - ImVeryGood/Loan GitHub Wiki
A页面代码:
render() {
return (
<View>
<Button
title="返回"
onPress={() => {
this.props.navigation.goBack();
DeviceEventEmitter.emit("key", "detail");
}}
/>
</View>
);
}
}
A页面接收
componentDidMount() {
DeviceEventEmitter.addListener("key", data => {
this._refresh(data);
});
}
_refresh(data) {
const _this = this;
_this.setState({
data: data
});
}
1.引入:
import { DeviceEventEmitter} from "react-native";
2.设置监听,并携带数据(参数一,是key,参数2是value):
DeviceEventEmitter.emit("key", "detail");
3.添加监听接收数据:
DeviceEventEmitter.addListener("key", data => {});
示例图:
从A跳转到B 并返回detail,显示
