当我在我的sveltekit项目中使用Firebase时,我如何修复错误窗口未定义,因为其他原因我无法将其挂载,并试图绕过它?你有什么 idea ,或者有没有办法让我把初始化放在装载上,同时仍然把数据发送到装载之外
<script>
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getFirestore } from "firebase/firestore";
import { onMount } from 'svelte';
import { collection, addDoc } from "firebase/firestore";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
let song = 'song';
const firebaseConfig = {
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore(app);
async function sendSong(){
try {
const docRef = await addDoc(collection(db, "songs"), {
title: {song},
atist: "test"
});
console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
}
</script>
<input bind:value={song}>
<style>
</style>