簡體   English   中英

如何從 firebase 數據庫調用 push() function

[英]How to call push() function from firebase database

我試圖從推送 function 中獲取唯一密鑰,但每當我調用它時,我都會收到此錯誤:Uncaught TypeError: postsRef.push is not a function at HTMLFormElement。 這些是我的進口商品:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
import { getDatabase, set, ref, update, onValue, remove, push } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-database.js";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, onAuthStateChanged, signOut } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-auth.js";
    

這些是我用來調用推送 function 的行:

const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const postsRef = ref(db, 'devices/');
const newPostRef = postsRef.push();

希望大家幫幫我,謝謝

push現在是頂級 function,不再是參考中的方法。

由於您已經在導入push ,因此可以將其用作:

const newPostRef = push(postsRef);

這里的變化非常機械:從object.operation()更改為operation(object) ,這是從舊版本 Firebase SDK 到 v9 及更高版本時的常見模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM