Component
可以在Component的Constructor中設(shè)置成員變量
// 構(gòu)造
constructor(props) {
super(props);
// 初始狀態(tài)
this.state = {
switchOn: false,
selectedLanguage: 'java',
...
key:value
};
}
在render()中的各個(gè)組件中的屬性中,可以使用
this.state.key
獲得該key的值,可以使用
this.setState({key:value});
設(shè)置屬性值。
props
你可以使用
<Demos navigator={navigator}/>
把相關(guān)的數(shù)據(jù)傳到Demos這個(gè)視圖中,然后在Demos中獲取到navigator這個(gè)屬性
<TouchableWithoutFeedback
onPress={()=>{
this.props.navigator.push({index:3});
}
}>