我正在使用React Native開發示例應用程序。我的問題是,我獲取的登錄憑據保存在登錄頁面localstorage()
異步存儲中,該值存儲在index.ios.js
文件中,但值顯示爲空。React-native IOS和Android中的自動登錄問題
中的任何一個,請告訴我,當我登錄到go_to_main
頁面,顯示login
屏幕和主屏幕後,這是我的主要問題
顯示我可以得到index.ios.js
文件中的值之後。這裏是我的代碼:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
AsyncStorage,
View
} from 'react-native';
import NavigationExperimental from 'react-native-deprecated-custom-components';
var loginScene //= require('./src/bundles/Login/scenes/LoginScene/index.js');
var SplashScreen = require('@remobile/react-native-splashscreen');
class SampleApp extends Component {
constructor(props) {
super(props);
this.state = {
email:'',
userName:''
}
}
componentWillMount() {
AsyncStorage.getItem('Email',(err,Email)=>{
if(Email == null){
}
else{
AsyncStorage.getItem('userName',(err,userName)=>{
if(userName == null){
}
else{
this.setState({
email:Email,
userName:userName
})
}
}).done()
}
}).done()
}
render() {
if(this.state.email != null){
loginScene = require('./src/bundles/Dashboard/scenes/koopiMainScene/index.js');
}
else{
alert("email1111:"+this.state.email)
loginScene = require('./src/bundles/Login/scenes/LoginScene/index.js');
}
return (
<View style={{flex:1,backgroundColor:'white'}}>
<NavigationExperimental.Navigator
initialRoute={{
component:loginScene,
passProps:{menuTitle:this.state.userName, Email:this.state.email}
}}
configureScene={(route) => ({
...NavigationExperimental.Navigator.SceneConfigs.HorizontalSwipeJump,
gestures: false
})}
renderScene={(route, navigator) =>{
return <route.component navigator={navigator} {...route.passProps} />;
}}/>
</View>
);
}
}
AppRegistry.registerComponent('SampleApp',() =>SampleApp);
請修改您的問題。儘可能糾正拼寫和語法錯誤。不要以大寫字母開頭。 –
只是爲了更好地理解你的問題,你想顯示登錄屏幕,如果用戶爲空? – gbland777
但值顯示爲空 – Lavaraju