无法从Firestore检索数据

时间:2020-09-13 10:57:11

标签: javascript web google-cloud-firestore

这是我的代码,我想从Firestore检索数据,但是发生错误(如下所示)。我该如何解决此错误或任何其他替代方法来检索数据? 错误:tasks.html:201未捕获的参考错误:在task.html:201中未定义firebase

<script>
      // Your web app's Firebase configuration
    var firebaseConfig = {
        apiKey: "AIzaSyD_h_EWO8z7ODYoj47CiF4hzf5qnjqE2Rc",
        authDomain: "blocktask-ae24a.firebaseapp.com",
        databaseURL: "https://blocktask-ae24a.firebaseio.com",
        projectId: "blocktask-ae24a",
        storageBucket: "blocktask-ae24a.appspot.com",
        messagingSenderId: "665923751623",
        appId: "1:665923751623:web:c0726bb66583506dceb8e2",
        measurementId: "G-X8RKV7R4K9"
      };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
      db.collection("users").get().then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            // doc.data() is never undefined for query doc snapshots
            console.log(doc.id, " => ", doc.data());
        });
    });
    
    
    </script>
    
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-analytics.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-database.js"></script>

enter image description here

enter image description here

0 个答案:

没有答案