我正在尝试初始化两个不同的firebase应用程序并导出它们。我尝试创建一个与此类似的不同文件,并将其导出。我们如何实际同时创建两个实例?任何对任何博客的引用都会很有帮助,因为我找不到合适的博客。
编辑它是为了让它变得清晰。我需要听另一个火力点是API.FIREBASE_XYZCONFIG
import API from "../api";
import firebase from "firebase/app";
import "firebase/firestore";
firebase.initializeApp(API.FIREBASE_CONFIG);
const firestore = firebase.firestore();
firestore.settings({ timestampsInSnapshots: true });
export default firestore;
这是它是如何在其中一个文件中完成并导出的。我所做的是
import API from "../api";
import firebase from "firebase/app";
import "firebase/firestore";
//import broadcastfirestore from './broadcastindex.js'
const a= firebase.initializeApp(API.FIREBASE_CONFIG);
const b= firebase.initializeApp(API.FIREBASE_BROADCAST_CONFIG,'broadcast');
const firestore = a.firestore();
const firestore2= b.firestore();
firestore.settings({ timestampsInSnapshots: true });
export default firestore;
上述初始化方法是否正确?
发布于 2019-05-26 00:46:04
参见https://firebase.google.com/docs/web/setup#multiple-projects。
// Initialize Firebase with a default Firebase project
firebase.initializeApp(firebaseConfig);
// Initialize Firebase with a second Firebase project
var otherProject = firebase.initializeApp(otherProjectFirebaseConfig, "other");
console.log(firebase.app().name); // "[DEFAULT]"
console.log(otherProject.name); // "otherProject"
// Use the shorthand notation to access the default project's Firebase services
var defaultStorage = firebase.storage();
var defaultFirestore = firebase.firestore();
// Use the otherProject variable to access the second project's Firebase services
var otherStorage = otherProject.storage();
var otherFirestore = otherProject.firestore();
https://stackoverflow.com/questions/56305634
复制相似问题