我想执行一些等同于以下内容的操作:
export default class LoadingScreen extends React.Component {
componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
this.props.navigation.navigate(user ? 'App' : 'Auth');
});
}
render() {
return (
<View style={styles.container}>
<Text>Loading</Text>
<ActivityIndicator size='large'></ActivityIndicator>
</View>
);
}
}我已经设置了我的路由,以便在进入Auth或App之前通过加载来检查用户的身份验证状态。当我添加mounted()时,加载文本和活动指示器没有显示。
<template>
<view class="container">
<nb-text>Loading</nb-text>
<activity-indicator size="large" color="#0000ff" />
</view>
</template>
<script>
import firebase from "firebase";
import Fire from "./../../api/firebaseAPI";
export default {
// Declare `navigation` as a prop
props: {
navigation: {
type: Object,
},
},
async mounted() {
await firebase.auth().onAuthStateChanged(function (user) {
this.navigation.navigate(user ? "App" : "Auth");
});
},
};
</script>当我运行上面的代码时,我得到一个白屏。
发布于 2020-12-29 04:09:40
也许我们应该将代码移入挂载到某个方法中。
<script>
mounted(){
this.checkAuth()
},
...
methods:{
async checkAuth(){
await firebase.auth().onAuthStateChanged(function (user) {
if(user){
this.navigation.navigate("Auth")
}else{
this.navigation.navigate("App")
}
});
}
}
</script>https://stackoverflow.com/questions/65285852
复制相似问题