简体   繁体   English

如何在React中更改实时数据库firebase URL

[英]How to change firebase realtime database URL in React

How can i change database url (firebase real time db) in code?如何在代码中更改数据库 url(firebase 实时数据库)? I would like to have option to choose which database you want (just different links)我希望可以选择你想要的数据库(只是不同的链接)

I have firebaseConfig.ts file where is my firebaseconfig variable that contains apikey, authDomain, databaseURL, ...我有 firebaseConfig.ts 文件,其中包含 apikey、authDomain、databaseURL 的 firebaseconfig 变量...

https://firebase.google.com/docs/projects/multiprojects#web https://firebase.google.com/docs/projects/multiprojects#web

You can have multiple firebase configs in an object like您可以在 object 中拥有多个 firebase 配置,例如

var configs = {"option1":{},"option2":{}}

and then initialise them all with different names like然后用不同的名字初始化它们,比如

var databases = {}
Object.keys(configs).map((name)=>{
  const app = firebase.initializeApp(configs[name],name);
  databases[name]=app;
})

then based on the choice you can access the database and access the db and change the values etc然后根据选择,您可以访问数据库并访问数据库并更改值等

const app = databases["option1"]
//access the realtime db and so on

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM