如何在Firebase上保存数据? [英] How to save data on Firebase?
问题描述
我参加了一个教程,以在React Native中在Firebase上保存日期.
I take a tutorial to save date on Firebase in React Native.
当我编译时显示错误为_firebase2.default.database.ref is not a function
When i compile it that show the error is _firebase2.default.database.ref is not a function
但是官方教程也是.ref
的问题.
https://firebase.google.com/docs/database/web/读写
But the question that offcial tutorial is .ref
too.
https://firebase.google.com/docs/database/web/read-and-write
任何人都可以教我如何解决该问题,谢谢.
Any one can teach me how to solve the issue , thanks in advance.
我在Firebase上的规则设置:
My rules setting on Firebase:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
在React Native中保存数据代码:
Save data code in React Native:
export const employeeCreate = ({ name, phone, shift }) => {
const { currentUser } = firebase.auth();
firebase.database.ref(`/users/${currentUser.uid}/employees`)
.push({ name, phone, shift });
};
推荐答案
您使用错了.
当您直接引用Firebase时,您应该像这样使用它
When u directly reference firebase, you should use it like this
firebase().database().ref('---whatever---')
这篇关于如何在Firebase上保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!