reactjs - 如何在反应原生中从导航中获取参数值
问题描述
this.props.navigation.navigate("ProductDeatils",
{params:{ price: this.state.GridListItems.price,
url: this.state.GridListItems.url}
});
I wanted to display these params values on the "ProductDeatils" page. please can anyone help me?
this.props.navigation.params 未定义。我试过这个 const { navigation } = this.props; const id = navigation.getParam('price') 不工作
解决方案
确保
this
指向组件而不是函数本身。哪个版本的反应导航?你配置
NavigationContainer
好了Stack.Navigator
吗Stack.Screen
?
例子:
应用程序.js
<NavigationContainer>
<Stack.Navigator
initialRouteName="Splash"
screenOptions={{
headerShown: false,
}}>
<Stack.Screen name="Login" component={Login} />
.......
登录.js
export default class Login extends React.Component {
componentDidMount() {
console.log(this.props.navigation) // It should work
}
.....
}
推荐阅读
- python - Python Pandas Dataframe Value Replace Using Regex
- arduino - 如何将注定要控制台的数据传递到Arduino中的char数组
- javascript - 反应:如何制作半个甜甜圈
- python - How can I create a function that calls another function and passes in an instance attribute as an argument?
- symfony - Deploying Symfony App To Elastic Beanstalk
- sql - How to create a table address and query it by states?
- c++ - Problem with parallel iterative merge sort using OpenMP
- mysql - postgres 或 Mysql 如何实现事务?是通过保持连接来完成的吗?
- django - 将变量传递到 url 以查询 DB
- python - 建立货币兑换矩阵