【发布时间】:2019-03-20 09:46:09
【问题描述】:
我正在尝试使用 react-native-router-flux 将数据从一个屏幕发送到另一个屏幕,但问题是我无法在屏幕的接收端接收数据。这是我的代码 sn-p:
在 router.js 中
<Router>
<Stack key="root">
<Scene
key="signup"
component={Signup}
title=""
initial={true}
hideNavBar={true}
/>
<Scene key="login" component={Login} title="" />
<Scene key="bottomtourbar" tabs={true} hideNavBar={true}>
<Scene
key="toursHome"
component={Tours}
title="Tours"
hideTabBar={true}
hideNavBar={false}
/>
<Scene
key="analytics"
component={Analytics}
title="Analytics"
hideNavBar={true}
hideNavBar={false}
/>
</Scene>
</Stack>
</Router>
在 Login.js 中,我使用下面的代码将参数传递给 toursHome 页面
Actions.toursHome({dataResponse:jsonResponse});
在 ToursHome.js 文件中我试图访问登录页面发送的参数
export default class Tours extends Component {
constructor(props) {
super(props);
};
render() {
const responseData = this.props.dataResponse;
console.log(responseData);
return (
<View style={styles.container}>
<ToursTab />
<View style={styles.TabbedContainer}>
<Text>{responseData}</Text>
</View>
<ToursBottom />
</View>
);
}
}
在控制台中它打印为未定义。
通过使用“Actions.login({dataResponse:jsonResponse});”从注册屏幕发送道具到登录有效,但是从登录到标签栏屏幕发送道具失败。 谁能帮我解决这个问题。
【问题讨论】:
-
"jsonResponse" 有一些数据或者你试图添加简单的字符串??
-
jsonResponse 由 json 数组组成,我在发送之前打印了 jsonResponse ,它显示数据存在。
标签: javascript react-native react-native-android react-native-ios react-native-router-flux