【发布时间】:2021-05-14 18:26:20
【问题描述】:
卡了好几天了。 代码实际上是从 google firebase 文档中复制而来的。
我想要的只是在 firebase 控制台中的 firestore 上写入和读取数据。 Firebase (Firestore) Javascript 一直显示错误。
谁能帮我写代码?我不需要花哨的代码或其他任何东西。只需在 Firestore 中写入和读取即可。
<!DOCTYPE html>
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
</head>
<body>
<script>
// Firebase App (the core Firebase SDK) is always required and must be listed first
import firebase from "firebase/app";
// If you are using v7 or any earlier version of the JS SDK, you should import firebase using namespace import
// import * as firebase from "firebase/app"
// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";
// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";
// TODO: Replace the following with your app's Firebase project configuration
// For Firebase JavaScript SDK v7.20.0 and later, `measurementId` is an optional field
const firebaseConfig = {
apiKey: "******",
authDomain: "retest-5308a.firebaseapp.com",
databaseURL: "https://retest-5308a-default-rtdb.firebaseio.com",
projectId: "retest-5308a",
storageBucket: "retest-5308a.appspot.com",
messagingSenderId: "125780245080",
appId: "1:125780245080:web:530259dc2a4b1362aae82d",
measurementId: "G-PNTZS15X9K"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");
// Initialize Cloud Firestore through Firebase
firebase.initializeApp({
apiKey: "********",
authDomain: "retest-5308a.firebaseapp.com",
projectId: "retest-5308a"
});
var db = firebase.firestore();
db.collection("users").add({
first: "Ada",
last: "Lovelace",
born: 1815
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
</script>
</body>
</html>
【问题讨论】:
-
能否请您至少发布错误?
-
好像有多个问题。当我修复其中一些时,错误会从其他地方弹出。请查看此网址。 retest-5308a.firebaseapp.com
标签: javascript firebase google-cloud-firestore