我的承诺如下:
function getprofile(id) {
if(firebase.auth().currentUser){
return firebase.database().ref('votes/' + id + '/' + firebase.auth().currentUser.uid)
.once('value')
.then(function(snapshot) {
if (snapshot.exists()){
console.log('ok1');
return '<span>user exists</span>';
}else{
console.log('ok2');
return '<span>user doesn\'t exist</span>';
}
});
}else{
console.log('ok3');
return Promise.resolve('<span>you must be logged</span>');
}
}
我以这种方式使用它:
getprofile(childSnapshot.key).then(data => { data })
因此,尽管使用了“ then”,但输出仍然是“ [object Promise]”,而不是跨度