2016-08-03 83 views
1

我第一次使用firebase並在它上面玩了兩天。看起來像在stackoverflow上的幾個例子,但沒有任何工作。Firebase不是構造函數錯誤(與反應一起使用firebase)

我的firebase版本是3.4.2。

 pushData(){ 

    var Firebase = require("firebase"); 
    var ref = new Firebase(" https://differentdatara.firebaseio.com"); 
    var usersRef = ref.child("fish1"); 
    usersRef.set({ 
     alanisawesome: { 
      date_of_birth: "June 23, 1912", 
      full_name: "Alan Turing" 
     }, 
     gracehop: { 
      date_of_birth: "December 9, 1906", 
      full_name: "Grace Hopper" 
     } 
    }); 

} 

當我運行代碼時,它給了我「Firebase不是構造函數」。

也嘗試與componentWillMount,但沒有任何工作。 我嘗試這樣

 componentWillMount(){ 
    console.log('yesdoneit'); 
    var Firebase = require("firebase"); 
    this.FirebaseRef = new Firebase(" https://passwordsaves-11b33.firebaseio.com"); 
     } 
+0

我不是一個JS人(還),但通常像'新',那''必須是一個類型。你正在使用一個變量。 Firebase對象不是有一個你應該使用的方法嗎? –

+0

我不能使用那些東西,因爲我寫我的代碼在jsx文件格式和工作反應鍋爐板 –

回答

4

因爲它是寫here

在新的SDK,你不再通過新的火力地堡實例化一個數據庫引用。相反,你將初始化通過firebase.initializeApp()的SDK:

var ref = new Firebase("https://databaseName.firebaseio.com"); 

AFTER:

var config = { 
    apiKey: "apiKey", 
    authDomain: "projectId.firebaseapp.com", 
    databaseURL: "https://databaseName.firebaseio.com" 
}; 

firebase.initializeApp(config); 

var rootRef = firebase.database().ref(); 

因爲,你的火力點的版本是3.4.2 ,你必須像在之後那樣做部分。

+1

讓我試着告訴你...謝謝 –

+0

我怎麼能找到我的apikey和認證域... –

+0

我只是知道我的數據庫網址..沒有別的...你能幫我找到AuthSomain和apikey –

相關問題