React native-Firebase“;错误:Reference.push失败:第一个参数在属性';messages.timestamp'&引用;
嗨,我正在尝试用firebase制作聊天应用程序。我正在学习这个教程 这是我的Fire.js。它与视频完全相同,但在我的电脑中不起作用React native-Firebase“;错误:Reference.push失败:第一个参数在属性';messages.timestamp'&引用;,firebase,react-native,Firebase,React Native,嗨,我正在尝试用firebase制作聊天应用程序。我正在学习这个教程 这是我的Fire.js。它与视频完全相同,但在我的电脑中不起作用 import firebase from 'firebase' class Fire{ constructor(){ this.init() this.checkAuth() } init=()=>{ if(!firebase.apps.length){ firebase.initializeApp
import firebase from 'firebase'
class Fire{
constructor(){
this.init()
this.checkAuth()
}
init=()=>{
if(!firebase.apps.length){
firebase.initializeApp
({
apiKey: "AIzaSyBK4qmCasdasfQAX9JSiaEeWh0-33f56IlrU",
authDomain: "chatko.rfirebaseapp.com",
databaseURL: "https://chatkor.firebaseio.com",
projectId: "chatkor",
storageBucket: "chatkor.appspot.com",
messagingSenderId: "452131431250",
appId: "1:4576325263250:web:6basd1698c9c68db75d54b",
measurementId: "G-8SJ1eeqdV1H"
})
}
};
checkAuth=() =>{
firebase.auth().onAuthStateChanged(user=>{
if(!user){
firebase.auth().signInAnonymously();
}
});
};
send=messages=>{
messages.forEach(item=>{
const message={
text:item.text,
timestamp: firebase.database.ServerValue.timestamp,
user: item.user
};
this.db.push(message);
});
};
parse=message=>{
const {user,text,timestamp}= message.val();
const {key:_id} =message;
const createdAt=new Date(timestamp);
return{
_id,
createdAt,
text,
user
};
};
get=callback=>{
this.db.on('child_added',snapshot=>callback(this.parse(snapshot)));
};
off(){
this.db.off();
};
get db(){
return firebase.database().ref('messages');
}
get uid(){
return (firebase.auth().currentUser || {}).uid;
}
}
export default new Fire();
它给出了这个错误
错误:Reference.push失败:第一个参数在属性“messages.timestamp”中包含未定义的内容。您没有将get关键字放在db和uid之前,因此它修复了此区域,但现在给出错误:Reference.push失败:第一个参数在属性“messages.timestamp”中包含未定义的内容