[英]Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) in vue.js
So I'm building mobile app via veu.js -> vuetify module using realtime database from firebase.所以我正在通过 veu.js 构建移动应用程序 -> 使用来自 firebase 的实时数据库的 vuetify 模块。
One of my views - Pract.vue need to retrive data from database.我的观点之一——Pract.vue 需要从数据库中检索数据。
<template>
<div class="pa-6 text-center">
<h1>Practice Mode</h1>
</div>
</template>
<script>
import firebase from "firebase";
import "firebase/database";
var ref = firebase.database().ref("ang");
</script>
I added firebase.initializeApp(firebaseConfig);我添加了 firebase.initializeApp(firebaseConfig); with data generated by firebase console to main.js file and import firebase from "firebase"使用 firebase 控制台生成的数据到 main.js 文件并从“firebase”导入 firebase
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify';
import firebase from "firebase";
// Xs in original code are real data
var firebaseConfig = {
apiKey: "X",
authDomain: "X",
databaseURL: "X",
projectId: "X",
storageBucket: "X",
messagingSenderId: "X",
appId: "X",
measurementId: "X"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
Vue.config.productionTip = false
new Vue({
router,
store,
vuetify,
render: h => h(App)
}).$mount('#app')
Console alert Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).控制台警报Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app)。
I've tried import firebase from 'firebase/app' both in view and main.js -> same alert.我已经尝试在视图和 main.js 中从 'firebase/app' 导入firebase -> 相同的警报。
I had this same issue when trying to use firebase in the router index.ts file.尝试在路由器 index.ts 文件中使用 firebase 时,我遇到了同样的问题。 I had to initialize firebase in index.ts to get it to work.我必须在 index.ts 中初始化 firebase 才能让它工作。
Try changing the import statement to尝试将导入语句更改为
import firebase from "firebase/compat/app";
I faced the same error while trying to have an separate file for accessing firebase services (which is neither a component nor a file created by vue-cli).我在尝试使用一个单独的文件来访问 firebase 服务时遇到了同样的错误(它既不是组件也不是 vue-cli 创建的文件)。 In my case it is sampleAPI.ts .在我的例子中是sampleAPI.ts 。 So to solve this, I had to import the above mentioned statement and then initialized the app in sampleAPI.ts that solved my problem.所以为了解决这个问题,我不得不导入上面提到的语句,然后在sampleAPI.ts中初始化应用程序,这解决了我的问题。
firebase.initializeApp(firebaseConfig);
You need to call你需要打电话
firebase.initializeApp();
before any calls to firebase can be made在调用 firebase 之前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.