首页 > 解决方案 > 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()')

标签: react-nativenavigation-drawerreact-navigation

解决方案


你可以试试这个

import { DrawerActions } from 'react-navigation';

this.props.navigation.dispatch(DrawerActions.closeDrawer());
this.props.navigation.dispatch(DrawerActions.openDrawer());

推荐阅读