0
我想開始反應,下面就firebaseBlog的例子中,我試圖運行下面的代碼片段,我明白,ReactFire:未捕獲的SyntaxError:意外的令牌| componentWillMount
Uncaught SyntaxError: http://localhost/h/js/test.js: Unexpected token (1:28)
> 1 | componentWillMount: function() {
| ^
2 | this.firebaseRef = firebase.database().ref("items");
3 | this.firebaseRef.on("child_added", function(dataSnapshot) {
4 | this.items.push(dataSnapshot.val());
和代碼被稱爲是這樣的。
componentWillMount: function() {
this.firebaseRef = firebase.database().ref("items");
this.firebaseRef.on("child_added", function(dataSnapshot) {
this.items.push(dataSnapshot.val());
this.setState({items: this.items});
}.bind(this)
);
}
'firebaseBlog'上的例子,請更具體一些,舉個例子?這個片段是一個有效的反應組件,但你仍然需要組件聲明的其餘部分。 – loganfsmyth