react-native - react-native 中的抽屉导航错误:undefined is not an object(评估'_this.props.navigation.openDrawer()')
问题描述
我已经设置了一个完美运行的导航抽屉,但是从今天早上开始我就遇到了这个错误。我不知道它是从哪里来的。因为我没有对抽屉做任何改动。我不能使用关闭抽屉的功能。
<Left style={{flex :1, flexDirection: 'row'}}>
<Icon
onPress={() => this.props.navigation.openDrawer()} name="menu"
tyle={{color: 'black', marginRight: 15,}} />
</Left>
错误是:
undefined 不是对象(评估 '_this.props.navigation.openDrawer()')
解决方案
你可以试试这个
import { DrawerActions } from 'react-navigation';
this.props.navigation.dispatch(DrawerActions.closeDrawer());
this.props.navigation.dispatch(DrawerActions.openDrawer());
推荐阅读
- macos - 无法使用 XQuartz mac 打开 GUI 应用程序
- ubuntu-18.04 - 在 ubuntu 18.04 中运行 odoo-11 时出现样式错误
- async-await - 我可以使用异步功能从不同的聊天中同时运行相同的命令吗?
- javascript - tsconfig 将 .sql 文件复制到 dist
- azure - 带有 for_each 的 Terraform 动态块
- java - 如果 Maven 属性不符合约定,则 Maven 构建失败
- python - Python:尝试将字符串转换为日期时间
- f# - 使用 Excel-DNA 或 Excel.Interop 将一些 Excel 图表系列值设置为 #N/A
- python - 根据另一组列对一组列进行排序
- ios - 如何根据 react-native-iap 购买中的条件重定向或加载视图