gpt4 book ai didi

javascript - 如何修复引用错误: firebase is not defined when all SDKs are in the HTML file

转载 作者:行者123 更新时间:2023-12-01 00:55:33 24 4
gpt4 key购买 nike

我正在尝试设计一个具有使用 Firebase 的登录表单的网站。

我按照文档 ( https://firebase.google.com/docs/web/setup?authuser=0 ) 并将 Firebase 所需的所有 JS SDK 以及 Firebase-Auth SDK 添加到我的 HTML 文件中。我还有一个用于 onclick 事件等的 JS 文件,我想在其中使用 firebase 库中的方法。

<div class="loginContainer">
<div class="card"></div>
<div class="card">
<h1 class="title">Login</h1>
<form>
<div class="input-container">
<input type="text" id="txtEmail" required="required" />
<label for="email_field">E-Mail</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input type="password" id="txtPassword" required="required" />
<label for="password_field">Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button onClick="login();" id="btnLogin"><span>Go</span></button>
</div>
</form>
</div>
</div>

<script src="assets/js/login.js"></script>

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use -->
<!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services -->
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/6.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
(the config from my Firebase console)
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
const auth = firebase.auth();

我希望 JS 文件能够识别 auth() 方法,但我得到的只是控制台中的“Uncaught ReferenceError: firebase is not Defined at login.js:2”。

最佳答案

在 Firebase sdk 脚本后面添加对 js 文件的引用:

//firebase sdk
<script src="https://www.gstatic.com/firebasejs/6.2.0/firebase-auth.js"></script>
<script src="assets/js/login.js"></script>

关于javascript - 如何修复引用错误: firebase is not defined when all SDKs are in the HTML file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56606142/

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