[英]firebase realtime database undefined function
我正在嘗試從實時數據庫中檢索我通過使用這樣的配置初始化應用程序來啟動
import {initializeApp} from 'firebase/app';
import {getDatabase} from 'firebase/database';
let config = {
apiKey: 'xxxxxxxxxxxx',
authDomain: 'xxxxxxxxxxxx',
...
};
const app = initializeApp(config);
const database = getDatabase(app);
然后當我嘗試使用database
變量時它崩潰了
componentDidMount() {
database
.ref(`master/tickets`)
.once('value', snapshot => {
var obj = snapshot.val();
console.log('obj :', obj);
})
.catch(error => {
console.log(error);
});
}
我也試過 firebase.database.ref() 它顯示錯誤找不到變量 firebase 我做錯了什么? 它在以前的版本中運行良好
隨着更新到 V9.0.0,Firebase Web SDK 發生了重大的重大變化。
有關如何將舊模式修改為新 API 的詳細信息,請參閱升級指南。
import { ref, get } from "firebase/database";
import { database } from "...";
/* ... */
componentDidMount() {
get(ref(database, 'master/tickets'))
.then(snapshot => {
const obj = snapshot.val();
console.log('obj :', obj);
})
.catch(error => {
console.log(error);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.