我已經開始遷移到 v9 Modular firebase。請看我的配置:
import { initializeApp } from 'firebase/app';
import { getDatabase } from "firebase/database";
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
..
};
const app = initializeApp(firebaseConfig);
// Get a reference to the database service
export const database = getDatabase(app);
然后在另一個檔案中,我制作了基本的 CRUD 函式。
import { database } from "./firebase"
export const insertTestData = () => {
return database.ref("test").set({name:"hello world"})
}
我收到以下錯誤:
Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_0__.database.ref is not a function
我錯過了什么嗎?
我不確定為什么它也沒有增加進口

uj5u.com熱心網友回復:
您正在ref()從 Modular SDK 匯入,但仍使用名稱空間語法。嘗試:
import { getDatabase, ref, set } from "firebase/database";
export const insertTestData = () => {
return set(ref(database, "test"), { name: "hello" })
}
確保您指的是檔案中代碼片段的“模塊化”選項卡
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/426136.html
標籤:javascript 火力基地 firebase-实时数据库
下一篇:如何定位同一物件的另一個值?
