0

我通过 react native 制作了天气应用程序。从 accuweather 获取天气数据并保存到状态。我需要在子页面(page1、2、3)中显示状态数据。

我怎样才能?请帮我。

https://github.com/charian/WhatTheWeather

4

3 回答 3

0

由于您没有提供任何特定代码,我只能假设您想将一些道具传递给页面。我在你的回购中找到了这篇文章:

navigateToScreen = (route) => () => {
    const navigateAction = NavigationActions.navigate({
      routeName: route
    });
    this.props.navigation.dispatch(navigateAction);
}

此功能需要将道具传递给您要导航到的页面。

你可以这样做this.props.navigation.navigate(route, {paramName: this.state.paramName});

在该页面上,您可以使用this.props.navigation.getParam(paramName, defaultValue)或访问这些道具this.props.navigation.state.params

于 2018-11-26T09:49:05.227 回答
0

您应该通过道具将您的状态数据发送到其他组件/页面。

于 2018-11-26T09:00:44.203 回答
0

在构造函数中定义你的状态。

constructor(props) {
    super(props);

    this.state = {
      experienceId: '',
      desktopDetail: this.props.navigation.state.params,
      clientId: '',
      installedVR: '',
      activeVR: '',
    };
  }

this.state.clientId使用组件中的任何位置访问您的变量。

于 2018-11-26T09:27:26.313 回答