我在第 43 行代碼中收到錯誤訊息。我哪里做錯了?還有我的資料庫圖片:這是我的資料庫
<script type="module">
import {
initializeApp
} from "https://www.gstatic.com/firebasejs/9.4.0/firebase-app.js";
import {
getDatabase,
set,
ref,
update
} from "https://www.gstatic.com/firebasejs/9.4.0/firebase-database.js";
import {
getAuth,
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
onAuthStateChanged,
signOut
} from "https://www.gstatic.com/firebasejs/9.4.0/firebase-auth.js";
const firebaseConfig = {
apiKey: ,
authDomain: ,
databaseURL: ,
projectId: ,
storageBucket: ,
messagingSenderId: ,
appId: ,
measurementId:
};
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const auth = getAuth();
const firebaseRef = firebase.database().ref("Users");
firebaseRef.once("value", function(snapshot) {
snapshot.forEach(function(element) {
console.log(element);
})
});
</script>
uj5u.com熱心網友回復:
這firebase.database().ref()是命名空間語法(在 V8 及之前使用),但您使用的是模塊化 SDK (V9 )。嘗試使用ref()和get()函式重構如下所示的代碼:
// ...imports
// import { get, ref } from "https://www.gstatic.com/firebasejs/9.4.0/firebase-database.js"
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const auth = getAuth(app);
const firebaseRef = ref(db, 'Users');
get(firebaseRef).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/384942.html
下一篇:不能超過類外變數的值
