react|react native navigationOptions中不能获取this
static navigationOptions = ({ navigation, navigationOptions,screenProps }) => {
const { params } = navigation.state;
return {
tabBarVisible: true,
headerRight:(
navigation.state.params.navigatePress()}>
//this.order()
点餐
)
}
};
// 点击完成按钮
order = ()=> {
alert('haha');
}
componentDidMount() {
// 处理数据源
this.props.navigation.setParams({navigatePress:this.order})
}
方法二:
在最外部声明:
let that;
在class内部:
constructor(props){super(props);
that =this;
}
在const * = StackNavigation({})中:
static navigationOptions = ({ navigation, navigationOptions,screenProps }) => {
const { params } = navigation.state;
return {
tabBarVisible: true,
headerRight:(
that.order()}>
点餐
)
}
};
order = ()=> {
alert('haha');
【react|react native navigationOptions中不能获取this】}
推荐阅读
- react|react 安装
- React.js学习笔记(17)|React.js学习笔记(17) Mobx
- React.js的表单(六)
- 【React|【React Native填坑之旅】从源码角度看JavaModule注册及重载陷阱
- react-navigation|react-navigation 动态修改 tabBar 样式
- Flutter|Flutter SwiftUI React 对比
- React|React refs和onRefs的使用
- 手写|手写 React-Native 方法调用式的 Modal 弹框、Toast 提示
- react组件通信
- react-native中Text包含Image大小问题