react-native - 将本机传递数据反应到另一个屏幕
问题描述
我需要将数据传递到另一个屏幕。这是导航堆栈中的代码
<Stack.Screen name="MyScreen" component={MyScreen} options={({ route }) => ({ title: 'Profile', url: 'http://www.google.com' })} />
在另一个屏幕上,这是我的代码,但我看不到参数。
import { Alert, View, Text, StyleSheet,} from 'react-native';
export default class MyScreen extends Component {
render() {
const { navigation } = this.props;
let mydata = navigation.getParam('url', 'http://');
alert(mydata);
}
}
解决方案
在反应导航 v5
你可以像这样设置initialParams
<Stack.Screen
name = "MyScreen"
component = {MyScreen}
initialParams = {{
myParam: 'Example value from param',
myAnotherParam: 5
}}
/>
然后在屏幕的脚本中,您可以像这样访问 myParam 或 myAnotherParam
this.props.route.params.myParam // 'Example value from param'
this.props.route.params.myAnotherParam // 5
推荐阅读
- openshift - 如何在命令提示符 Mac 中在线运行 openshift
- ios - pushViewController 时禁用导航栏透明度
- android - 牛津词典 Api 通过 EditText 搜索单词
- reactjs - Azure多个应用程序与反应,在浏览器中加载反应后无法访问其他应用程序
- excel - 具有动态范围的 VBA VLOOKUP
- php - Invision 电源板错误
- node.js - 使用 Jest 和 Mongoose 进行快速 API 测试
- asp.net-core - Autofac 和 Automapper - 已注册但未解析的配置文件
- java - 构造函数 Scanner(InputStream) 未定义
- save - pyside 读/写字典列表