gpt4 book ai didi

javascript - Firebase 未捕获引用错误 : firebase not defined

转载 作者:行者123 更新时间:2023-12-03 06:15:02 25 4
gpt4 key购买 nike

我在 OnsenUI/monaca 应用程序中连接我的 firebase 数据库时遇到问题。我查看了与此问题相关的其他线程,并确保我的调用已针对 firebase 3.x.x 进行了更新。但是,每次我尝试启动开发中的应用程序时,都会收到相同的 firebase not Defined 错误。我对这一切都很陌生,非常感谢任何帮助

index.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script>
//creates reference to firebase
var ref = new Firebase('https://monaca-cli-trial.firebaseio.com/');

// Initialize Firebase
var config = {
apiKey: "whateverapinumber",
authDomain: "myapp.firebaseapp.com",
databaseURL: "https://myapp.firebaseio.com",
storageBucket: "",
};
firebase.initializeApp(config);

var rootRef = firebase.database().ref();

</script>
<script src="https://www.gstatic.com/firebasejs/3.3.0/firebase.js"></script>

<script src="components/loader.js"></script>
<script src="lib/onsenui/js/onsenui.min.js"></script>
<script src="lib/javascriptstuff.js"></script>
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
<link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
<link rel="stylesheet" href="css/style.css">

我得到的错误指向第 19 行,即 firebase.initializeApp(config);

最佳答案

我在代码中详细发布了您有错误的地方。此外,我建议观看 firebase channel 上的视频。 https://youtu.be/k1D0_wFlXgo

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

<!-- 1. Duplicates. Outdated version-->
<!--<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>-->


<!-- 2. Install the new version-->
<script src="https://www.gstatic.com/firebasejs/3.3.0/firebase.js"></script>

<script>
// 3. Remove it is not necessary. Are registered in the databaseURL .
// var ref = new Firebase('https://monaca-cli-trial.firebaseio.com/');


var config = {
/* 5. Install apiKey*/ apiKey: "whateverapinumber",
/* 6 Replace authDomain: "myapp.firebaseapp.com" on authDomain: "monaca-cli-trial.firebaseapp.com" */ authDomain: "monaca-cli-trial.firebaseapp.com",
/* 7 Replace databaseURL: "https://myapp.firebaseio.com" on databaseURL: "https://monaca-cli-trial.firebaseio.com/" */ databaseURL: "https://monaca-cli-trial.firebaseio.com/",
storageBucket: "",
};
firebase.initializeApp(config);

var rootRef = firebase.database().ref();

</script>

<script src="components/loader.js"></script>
<script src="lib/onsenui/js/onsenui.min.js"></script>
<script src="lib/javascriptstuff.js"></script>
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
<link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
<link rel="stylesheet" href="css/style.css">

关于javascript - Firebase 未捕获引用错误 : firebase not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39147695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com