[React-Native]RN數據管理

Component

可以在Component的Constructor中設置成員變量

// 構造
constructor(props) {
    super(props);
    // 初始狀態
    this.state = {
        switchOn: false,
        selectedLanguage: 'java',
        ...
        key:value
    };
}

render()中的各個組件中的屬性中,可以使用

this.state.key

獲得該key的值,可以使用

this.setState({key:value});

設置屬性值。

props

你可以使用

<Demos navigator={navigator}/>

把相關的數據傳到Demos這個視圖中,然后在Demos中獲取到navigator這個屬性

<TouchableWithoutFeedback 
  onPress={()=>{
                  this.props.navigator.push({index:3});
                       }
                    }>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容