我正在尝试执行firebase firestore的入门指南,复制了所有内容:https://firebase.google.com/docs/firestore/quickstart?authuser=0。但不断收到Failed to load in chrome的错误。谁知道我做错了什么?非常感谢。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>firebase</title>
<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase-firestore.js"></script>
</head>
<body>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyB__YWuIm8QjQdFLvZ1qv6P5-yVkYv7I9g",
authDomain: "fireapp-b79d6.firebaseapp.com",
databaseURL: "https://fireapp-b79d6.firebaseio.com",
projectId: "fireapp-b79d6",
storageBucket: "fireapp-b79d6.appspot.com",
messagingSenderId: "1050532546787"
};
firebase.initializeApp(config);
var db = firebase.firestore();
db.collection("users").add({
first: "Ada",
last: "Lovelace",
born: 1815
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
</script>
</body>
</html>
答案 0 :(得分:0)
你如何运行你的代码?如果我建议您使用firebase CLI运行firebase serve命令来为项目提供服务。 (命令行界面。)如果您不熟悉firebase CLI,请使用安装firebase CLI并为项目提供服务的链接。 firebase.google.com/docs/cli,当您使用firebase cli时,您的项目将在以下位置投放:http://localhost:5000/