美文网首页
React Navite中的一些语法

React Navite中的一些语法

作者: _RG | 来源:发表于2019-10-30 15:32 被阅读0次

    static 定义的数据类型不能在函数内部, 否则会报错
    const 声明的类型不能在函数外部,否则会报错

    访问静态变量或静态函数,直接以“类名.变量名(函数名)”的方式访问。不能以“this.变量名(函数名)”的方式访问。

    以下是开发中测试所得, 并非官方文档,如果错误, 还望指正

    class ListScreen extends React.Component{
    
        static  navigationOptions = ({navigation}) => {
            return {title : navigation.getParam("otherParamsrrr","默认列表")}
        }
    
        render(){
    
            const {navigation} = this.props;
    
            return <View>
                <Text>列表</Text>
                <Button
                    title="返回首页"
                    onPress={()=>this.props.navigation.navigate("Home")}></Button>
                <Button title="进入详情" onPress={()=>this.props.navigation.navigate("Detail")}></Button>
                <Text>
                    itemId: {JSON.stringify(navigation.getParam('itemId', 'NO-ID'))}
                </Text>
                <Text>
                    otherParam:
                    {JSON.stringify(navigation.getParam('otherParamsrrr', 'default value'))}
                </Text>
            </View>
        }
    }
    

    相关文章

      网友评论

          本文标题:React Navite中的一些语法

          本文链接:https://www.haomeiwen.com/subject/hogovctx.html