我在与 expo 本机反应时有一个错误:"syntax error unexpected token"错误。有什么帮助来解决吗?谢谢



我尝试添加括号或分号,但出现错误:

语法错误:意外的令牌

如何实现此功能并使这项工作正确?我的完整代码:

另外,为什么它不起作用?

从"反应"导入反应,{ 组件 }; 从"反应本机"导入 { 文本、活动指示器、视图、按钮、文本输入、样式表、可触摸不透明度、维度、应用注册表、平台、状态栏、异步存储 }; 从'react-navigation'导入{createAppContainer, createSwitchNavigator }; 从 'react-navigation-stack' 导入 { createStackNavigator };

const userInfo = {username: 'admin', password: 'pass12345'} 
class HomeScreen extends Component { 
static navigationOptions = { header: null } 
constructor(props) { 
super(props);
this.state = { username: '', password: '' }
}
render() { 
return ( 
<View style={styles.container}> 
<Text>News</Text>
<TextInput
style={styles.input} 
placeholder={'Username'} 
onChangeText={(username)=>this.setState({username})} 
value={this.state.username} 
autoCapitalize="none" 
/> 
<TextInput 
style={styles.input} 
placeholder={'Password'} 
secureTextEntry={true} 
onChangeText={(password)=>this.setState({password})} 
value={this.state.password} 
/> 
<View> 
<TouchableOpacity 
style={styles.btnLogin} 
onPress={this._login} 
//onPress={() => this.props.navigation.navigate('Details')} 
>
<Text style= {styles.text}>Login</Text> 
</TouchableOpacity>
<TouchableOpacity onPress={() => alert("Signup Works")} > 
<Text style={styles.btnTxt}>Signup</Text> 
</TouchableOpacity> 
</View> 
</View> 
); 
} 
} 
class DetailsScreen extends Component { 
render() { 
return ( 
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> 
<Text>Details Screen</Text> 
</View> 
); 
} 
} 
const RootStack = createStackNavigator({ 
//Home: HomeScreen, 
Details: DetailsScreen 
}, {//initialRouteName: 'Home'} ); 
defaultNavigationOptions:{
headerStyle:{
backgroundColor: '#1e90ff'
},
headerTitleStyle: {
textAlign:'center',
flex: 1
}
}
},
};

const AuthStack = createStackNavigator({Home: HomeScreen});
class AuthLoadingScreen extends Component {
constructor (props){
super(props);
this._loadData();
}
render(){
return(
<View>
<ActivityIndicator/>
<StatusBar barStyle="default"/>
</View>    
);
}
_loadData = async() => {
const isLogged = await AsyncStorage.getItem('isLoggedIn');
this.prop.navigation.navigate(isLoggedIn !== '1'? 'Auth':'App');
}
}

export default createAppContainer(
createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: RootStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
}
)
);
_login = async() => { 
if (userInfo.username === this.state.username && userInfo.password === this.state.password) { 
//alert('Logged In'); 
await AsyncStorage.setItem('isLoggedIn', '1'); 
this.props.navigation.navigate('Details') 
} else { 
alert('Username or Password is incorrect.'); 
} 
} 

const styles = StyleSheet.create({ 
container:{ flex:1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#00bfff', }, 
btnLogin: { flex: 0.5, height: 45, borderRadius: 25, fontSize: 16, justifyContent: 'center', marginTop: 20 }, 
btnTxt:{ }, 
input:{ justifyContent: 'center', width:"90%", padding: 15, marginBottom: 10 } 
});

世博会错误

乍一看,这似乎是一个问题:

}, {//initialRouteName: 'Home'} ); 

您已经注释掉了结束}和关闭)

相关内容

最新更新